I have some JSON data:
{
"113":{"id":"113","title":"Coal","hex":"4f4f4f"},
"116":{"id":"116","title":"White","hex":"fdfbf7"},
"115":{"id":"115","title":"Greylead","hex":"b3b3b3"}
}
Which is in the markup on a data attribute I can access like so:
var arr = $("#element).data('arr');
And then do stuff with each item. Like so:
$.each( arr, function( index, obj ){
console.log( obj.title + ' is #' + obj.hex );
}
But the order of the items in the data isn't being preserved.
$.each
seems to iterate through by the leading number of each item in the data, NOT the order that items are actually in the array. I get my output in the numerical order 113, 115, 116 instead of 113, 116, 115 (which is the actual order of the items in the data).
How would I iterate through the items in the actual order?