I have the following piece of code:
function() {
$.getJSON(
myurl + '/get_data',
function(data) {
function sort_data(first, second) {
return (first.sort - second.sort);
}
console.log(data);
console.log(data.sort(sort_data));
}
... snipped for brevity
Data is array of objects, each object has sort field, which is integer. By default they are all in random order.
So after executing the code above It tells me that data before and after sort is identical. At least both console.log outputs are the same (and they are sorted). However, if I skip the sorting part and just console.log(data.objects) - it's different and is unsorted.
It seems like sort is executed first, while console.logs are executed after. Why is it like that? Thanks!