Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any major browsers that do not preserve insertion order in a JavaScript Object?

Can I depend on the following code alerting b before a?

var x = {}
x['b'] = 1
x['a'] = 0
for(var i in x) {
    alert(i)
}
like image 355
700 Software Avatar asked May 26 '11 13:05

700 Software


1 Answers

Are there any major browsers that do not preserve insertion order in a JavaScript Object?

At least one major browser did until recently (I think the V8 engine didn't preserve order).

Can I depend on the following code alerting b before a?

No. The spec says that there is no order.

like image 69
Quentin Avatar answered Nov 09 '22 23:11

Quentin