There is no such thing as an "array of objects" in JavaScript. There are objects, and there are arrays (which, of course, are also objects). Objects have properties and properties are not ordered in any particular way.
In other words, if you have:
var obj = { a: 1, b: 2, c: 3 };
there is no guarantee that the for ... in loop will visit properties in the order "a", "b", "c".
Now, if you have an array of objects such as:
var arr = [ { a: 1 }, { b: 2 }, { c: 3 } ];
then it is a regular array and you can undo it. The .reverse() method mutates the array, so you do not reinstall it. If you have an array of objects (or a real array of any values), then you should not use for ... in to iterate through it. Use a numeric index.
edit - he indicated in a useful comment that .reverse() returns a reference to the array, so reassigning will not hurt anything.
source share