How to sort array by num property in this JavaScript array.
var data = [{
005: { `num`: 1360487},
047: { `num`: 2519472},
061: { `num`: 1559115},
081: { `num`: 2232710},
085: { `num`: 54956 }
}];
How to sort array by num property in this JavaScript array.
var data = [{
005: { `num`: 1360487},
047: { `num`: 2519472},
061: { `num`: 1559115},
081: { `num`: 2232710},
085: { `num`: 54956 }
}];
What you are manipulating is an array containing 1 object, not an array of objects. You should probably change the structure of data to make it easier to manipulate, an example would be:
var data = [
[005, { num: 1360487}],
[047, { num: 2519472}],
[061, { num: 1559115}],
[081, { num: 2232710}],
[085, { num: 54956 }],
];
data.sort(
function (firstElem, secondElem) {
return firstElem[1].num - secondElem[1].num;
}
);
// data is sorted