This is not an array. This is an object. And as such, there is no guaranteed order.
To guarantee some sequence, you can define a sequence in an array, and then iterate over this array by selecting the index of each array value from the object.
arr = {}; arr[1] = "one"; arr[2] = "two"; arr[105] = "three"; arr[4] = "four"; var order = [1,2,105,4]; $.each(order, function(i,val) { console.log( val + '=>' + arr[ val ] ); });
source share