$ .ajax get object after json_encode ($ arr) from php, but how to get key and value in jQuery?
1
In PHP:
$arr = array( 10=>"ten", 5=>"five", 2=>"two"); return json_encode($arr);
In JS - $ .ajax ():
success: function(data){ console.log(data);}
2
What I see in the console:
Object {2: "two", 5: "five", 10: "ten"},
I want to use for(var i=0; i< data.length,i++), but failed.
Finally, it works as follows: for(var i in data)
3
My question is: why is the array sorted? I want the array to be kept unsorted.
Does anyone help me?
+4