Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node.js not working Object.keys

var list = {"you": 100, "me": 75, "foo": 116, "bar": 15};
keysSorted = Object.keys(list).sort(function(a,b){return list[a]-list[b]})
alert(keysSorted);     // bar,me,you,foo

from Sorting JavaScript Object by property value

I'm doing Object sorting. Above source working in Javascript. But not working in Node.js. I have an error like this.

keysSorted = Object.keys(list).sort(function(a,b){return list[a]-list[b]})
                    ^
TypeError: Object.keys is not a function

I don't know why. Please help me.

like image 618
firepunch Avatar asked Nov 13 '16 08:11

firepunch


1 Answers

Most likely, you are using an out-dated Node.js version, v0.10 or v0.12. To check the version try running node -v.

This old version doesn't support Object.keys. You can check supported features for every Node.js versions here.

My advice is to update to Node.js version to 6.9.1. This version is current LTS (Long-term support).

like image 117
galkin Avatar answered Nov 16 '22 02:11

galkin