TypeError: Object.entries is not a function
I copied and pasted the following code into a blank WebStorm javascript project:
var obj = {a: 5, b: 7, c: 9};
Object.entries(obj).forEach(([key, value]) => {
console.log(key + ' ' + value); // "a 5", "b 7", "c 9"
});
this code is copied from the example code on MDN for the Global Object entries method. It works fine when pasted into a CodePen, but throws this error in Webstorm:
/usr/local/bin/node /Users/Scott/Projects/JavaScript/test.js
/Users/Scott/Projects/JavaScript/test.js:2
Object.entries(obj).forEach(([key, value]) => {
^
TypeError: Object.entries is not a function
at Object.<anonymous> (/Users/Scott/Projects/JavaScript/test.js:2:8)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:389:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:504:3
Process finished with exit code 1
What am I doing wrong in my IDE/Project configuration? This is a built-in Javascript method and I'm running into the same error with other methods of the Global Object. e.g.
console.log(Object.values(obj));
Please sign in to leave a comment.
What Node.js version do you use?
See https://stackoverflow.com/questions/43858714/typeerror-object-entries-is-not-a-function
I'm using Node 6.11.2 on OSX Sierra. So I'm guessing I would need a later version of Node. Assuming my version of Node supports the feature, is there a Webstorm limitation. I'm learning Javascript and just trying to get a handle on things. Thanks for the link.
The error has absolutely nothing to do with WebStorm, it appears in runtime when running your code with Node.js. So this is not an IDE limitation