I have a web service that returns a JSON encoded array of data. I then use jQuery's .each()
function to iterate through that array but in Firefox it iterates down while in Chrome it iterates up.
the data that come sback from the web service is:
{
"data": {
"610": {
"id": "610",
"url": "a url 1",
"description": "XXX YYY",
"toc": "0000-01-00",
"active": "1"
},
"608": {
"id": "608",
"url": "a url 1",
"description": "ytttgffrr",
"toc": "0000-01-00",
"active": "1"
},
"607": {
"id": "607",
"url": "a url 3",
"description": "rtretert3",
"toc": "0000-01-00",
"active": "1"
},
"606": {
"id": "606",
"url": "a url 4",
"description": "xxxwwww",
"toc": "0000-01-00",
"active": "1"
},
...
}
}
Firefox goes 610 -> 606 while chrome fors 606 -> 610.
Any ideas why and what I can do about it?
Properties in objects have no inherent order. The ECMAScript specification doesn’t guarantee that for…in
statements will traverse the object by its properties in alphabetical order. jQuery.each
uses for…in
under the hood when used on objects.
If the order is important to you, use an array instead of an object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With