I have an array that looks like this:
{ username: 'usernameadw',
rank: 'rookie',
points: 891
},
{ username: 'username662',
rank: 'rookie',
points: 999
},
{ username: 'usernameabd8a',
rank: 'knight',
points: 2393
},
{ username: 'usernamev88',
rank: 'mage',
points: 1673
},
{ username: 'abcusername123',
rank: 'mage',
points: 1483
}
I am wondering how I can split these arrays into arrays like "mageArray", "knightArray", rookieArray", and then with each array, sort them by how many points each object has from highest to lowest?
I have tried using this code so far but it's not working. What I tried to do was create a new object from the large array with the info, and then push it to another array if the rank name matched
var obj = new Object({
username: usersRows[i].username,
rank: usersRows[i].rank,
points: usersRows[i].points
});
if (usersRows[i].rank === 'mage') { mageArray.push(obj); }