0

If I have this code :

o["a"]=1;
o["b"]=1;
o["c"]=1;
o["d"]=1;


for (var k in o)
{
  alert(k)
}
  • Would it always(cross browser) be alerted in the same order as the attribute were added ?

  • And what about this ? (same question)

    var o={a:1,b:1,c:1,d:1} ?

Royi Namir
  • 144,742
  • 138
  • 468
  • 792

1 Answers1

2

No. The order is not specified. From the spec:

The mechanics and order of enumerating the properties ... is not specified.

James Allardice
  • 164,175
  • 21
  • 332
  • 312