Object Iteration In Reverse (javascript)
How can I iterate over a javascript object, from back to front. The object looks like this. {'33':140, '34':100, '35':120, '36':200} I want it to display like this... 36 | 200 35 |
Solution 1:
A fairly modern version would look like this:
Object.keys(obj).sort(function (a, b) {
returnNumber(b) - Number(a);
}).forEach(function (current) {
console.log(current + ' | ' + obj[current]);
});
Similarly, but with a little bit more code, it could be written for older browsers, too. Or you use shims.
Post a Comment for "Object Iteration In Reverse (javascript)"