So I have a JavaScript object like this:
foo = {
"one": "some",
"two": "thing",
"three": "else"
};
I can loop this like:
for (var i in foo) {
if (foo.hasOwnProperty(i)) {
// do something
}
}
Which will loop through the properties in the order of one
> two
> three
.
However sometimes I need to go through in reverse order, so I would like to do the same loop, but three
> two
> one
.
Question:
Is there an "object-reverse" function. If it was an Array, I could reverse or build a new array with unshift
but I'm lost with what to do with an object, when I need to reverse-loop it's properties. Any ideas?
Thanks!