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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With