Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Object.values() on server side in Node.js

Object.values() received following error:

TypeError: Object.values is not a function.

From this question on stackoverflow - I see that Object.values() is not supported in all browsers.

But I am using the function in Node.js on server side - How can I use Object.values() in Node.js it seems so intuitive like Object.keys()?

like image 452
npr Avatar asked Nov 04 '16 11:11

npr


People also ask

How do you display an object in NodeJS?

Answer: Use console. log() or JSON. stringify() Method You can use the console. log() method, if you simply wants to know what's inside an object for debugging purpose. This method will print the object in browser console.

Is NodeJS server-side or client side?

Node. js is an open source JavaScript runtime environment that lets developers run JavaScript code on the server. If that's too complex for you to understand then you should think of it this way: Node. js is JavaScript that runs outside the browser — on the server.

How do you access data in NodeJS?

To access the database from Node. js, you first need to install drivers for the database you want to use. The following table lists important relational databases and respective drivers. The following table lists important NoSQL databases and respective drives .


1 Answers

Object.values is a new feature in ES2017. It is very bleeding edge. Node.js has full support for it from version 7.0.

6.8.1 supports it, but it is considered unstable and is locked behind the --harmony flag.

You can either:

  • Upgrade to the latest Node.js LTS and use --harmony
  • Upgrade to the latest Node.js Current
  • Use a polyfill
like image 54
Quentin Avatar answered Oct 03 '22 19:10

Quentin