I'm parsing JSON and getting an array of objects with javascript. I've been doing this to then append an element for each object:
for(o in obj){ ... }
But I realized that for a certain situation I want to go backwards through the array. So I tried this before the for loop:
obj = obj.reverse();
However this isn't reversing the order of the objects in the array. I could simply put a count variable in the for loop to manually get the reverse, but I'm puzzled as to why reverse doesn't seem to work with object arrays.
obj = obj.reverse()is unecessary, becausereverseis a mutator method. You can simply doobj.reverse().for...in. Use a normalforloop, then you could simply iterate over fromarr.lengthto0as well. It does not matter at all which data types are contained in the array. If you actually have an object and not an array then you cannot reverse the order anyways (there is no order). Please provide the value ofobj.