There are lots of questions similar to this but I couldn't find any quite like this. Here is my code.
for (var i = 0; i < count_batters; i++) {
var post = {
player_name: jsonData[i].player_name,
fantasy_points: jsonData[i].avg_fpts_fd
}
console.log(post);
function compare(a,b) {
if (a.fantasy_points < b.fantasy_points)
return -1;
if (a.fantasy_points > b.fantasy_points)
return 1;
return 0;
}
post.sort(compare);
I want to sort "post" by "fantasy_points". It is sorted by player_name by default. I have tried .sort() which doesn't work on this object. The error the above code gives is undefined is not a function