When using a for .. in
loop to iterate over the members of an object, the order of enumeration is determined by the implementation. However, if the object remains unchanged, is it guaranteed that iterating over it twice in the same browser during the same page visit will produce the same order?
The code snippet below aims to test this property. The main question is whether a browser might throw "not the same":
a = []
b = []
for (var e in obj)
a.push(e);
for (var e in obj)
b.push(e);
// Are the contents of arrays a and b the same?
// Or is the consistency of the order implementation dependent?
for (var i = 0; i < a.length; i++)
if (a[i] !== b[i])
throw "not the same";
I am curious about both the theoretical answer based on specifications and the practical outcome on current browsers.
To clarify, I am not inquiring about consistency across different browsers. My focus is on whether the order remains consistent across multiple iterations of the same object within a single web page visit when the object remains unaltered.