mirim mirim - 1 year ago 163
Node.js Question

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.

Answer Source

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).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download