0

Is it true that in Javascript the order of the for in loops is determined by the priority field in the objects?

var objs={
    foo:{priority:0,name:"foo"},
    bar:{priority:1,name:"bar"},
}
for(key in objs){
    console.log(objs[key].name)
}

First I see bar, then foo.

So is it true?

ericj
  • 1,847
  • 22
  • 36

1 Answers1

3

No, usually the loop over the properties of an object in the order in which they were defined, however it's not a standard.

ChrisP
  • 46
  • 2
  • Yes, that's it. I was confused, because if you print the object which is a collection of key:value's, with let's say keys "foo" and "bar", the "bar" item is shown first, because that's how the print function apperently works, so it doesn't show the order in which these two items are inserted. – ericj Apr 25 '14 at 11:14