Elements order in a “for (… in …)” loop

Does the “for…in” loop in Javascript loop through the hashtables/elements in the order they are declared? Is there a browser which doesn’t do it in order?
The object I wish to use will be declared once and will never be modified.

Suppose I have:

var myObject = { A: "Hello", B: "World" };

And I further use them in:

for (var item in myObject) alert(item + " : " + myObject[item]);

Can I expect ‘A : “Hello”‘ to always come before ‘B : “World”‘ in most decent browsers?

10 Answers
10

Leave a Comment