I have the following array of objects
var unsorted = [
{id:1, score_on_kilo:15},
{id:2, score_on_kilo:18},
{id:3, score_on_kilo:3},
{id:4, score_on_kilo:100},
];
var sorted = unsorted.sort(function (a, b) {
return parseInt(a.score_on_kilo) > parseInt(b.score_on_kilo);
});
When i check on the console.log(sorted)
an getting
[
{id:1, score_on_kilo:15},
{id:2, score_on_kilo:18},
{id:3, score_on_kilo:3},
{id:4, score_on_kilo:100},
]
What am i missing out as also on the sorted even changing to return parseInt(a.score_on_kilo) - parseInt(b.score_on_kilo);
still doesnt sort the arrays
I expected this to have
[
{id:4, score_on_kilo:100},
{id:2, score_on_kilo:18},
{id:1, score_on_kilo:15},
{id:3, score_on_kilo:3},
]
What am i missing?