How do you stop Chrome and Opera sorting JSON objects by Index ASC? How do you stop Chrome and Opera sorting JSON objects by Index ASC? google-chrome google-chrome

How do you stop Chrome and Opera sorting JSON objects by Index ASC?


Had same problem, followed dmc's solution but just added a space in front of the int value to make it a string.

The advantage of using a space rather than another non numeric character is that the subsequently POSTed value can be used directly in a mySQL search clause without having to remove it again.


Different browsers handle objects in different ways, my fault was to try and use the order I built an object as a reference where I shouldn't.


Changing integer to string didn't work for me (Chrome, jQuery 1.7.1).So to keep the order (yes, it's object abusing), I changed this:

optionValues0 = {"4321": "option 1", "1234": "option 2"};

to this

optionValues0 = {"1": {id: "4321", value: "option 1"}, "2": {id: "1234", value: "option 2"}};