sorting - Object iteration in reverse (javascript) -
how can iterate on javascript object, front.
the object looks this. {"33":140, "34":100, "35":120, "36":200}
i want display this...
36 | 200 35 | 120 34 | 100 33 | 140
i tried sorting first displaying, sorts second number, not key. how either iterate front, or reverse sort based on key.
i realize pretty simple, im getting pretty frustrated it....
a modern version this:
object.keys(obj).sort(function (a, b) { return number(b) - number(a); }).foreach(function (current) { console.log(current + ' | ' + obj[current]); });
similarly, little bit more code, written older browsers, too. or use shims.
Comments
Post a Comment