I'm trying to sort an 2d object by a value inside the 2nd object. But when i do that the console.log before the sorting returns the exact same (already sorted) value as after the sorting.
Here is my example code
var result = {
"success": true,
"instances": [
{
"InstanceId": "428",
"content": "1234"
},
{
"InstanceId": "429",
"content": "4321"
},
{
"InstanceId": "427",
"content": "im a rebel"
}
]
}
var old = result.instances;
var newww = result.instances;
console.log(old, 'old');
newww.sort(function(a, b) {
return a['InstanceId'] - b['InstanceId'];
});
console.log(newww, 'new');
Example: https://jsfiddle.net/cgovohgL/
Thanks for your time
Added info: console.dir gives the same result