1

I'm trying to come up with a js object minification function, one that would take an object and turn it into something like "VS4g3as" or whatever. The unminification would require the object prototype since I'm only storing the values.

Anyways, question is that if I run a for-in loop on an object like "for (var key in object)...", are the keys returned guaranteed to always be in the same order regardless of browser, platform, weather or whatever?

I'm trying to decide whether or not I need to enforce some kind of ordering like alphabetical.

user81993
  • 5,209
  • 3
  • 26
  • 51
  • 2
    This might help you: http://stackoverflow.com/questions/280713/elements-order-in-a-for-in-loop – nikoskip Mar 30 '16 at 12:58
  • You probably will want to do something like `Object.keys(yourObject).sort().reduce( function(str, val){ return str + yourObject[val]; },"");` if you want to do it by sort order of the keys. – epascarello Mar 30 '16 at 13:02
  • @maioman from [mdn](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/keys) : "The Object.keys() method returns an array of a given object's own enumerable properties, in the same order as that provided by a for...in loop" – Kaiido Mar 30 '16 at 13:11

0 Answers0