If you care about the order, you should provide a list in a JSON response.
But in this case, your data is incorrect,
response = [{"3":"Andy"},{"1":"Bruce"},{"4":"Charlie"},{"2":"David"}]
And then:
$.each(response ,function(index,v){ console.log(v) // or //console.log(data[index]) //And to get the number and name, you must do some trick for (let [key, value] of Object.entries(v)) { console.log(number,value); } })
The best solution
You must use the key for the number, what is this number? id , rank ?
response = [{"id":3,"name":"Andy"},{"id":1,"name":"Bruce"},{"id":4,"name":"Charlie"},{"id":2,"name":"David"}]
And then:
$.each(response ,function(index,value){ console.log('Id:',value.id,'Name:',value.name); });
source share