npr npr - 1 month ago 6
Javascript Question

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()
?

Answer

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