I am trying to sort an object so that the property with the most votes comes first. Here's my data structure
I have found some articles on how to do this and I have created a new array and am pushing the votes value into it as well as the player object. The problem I am having is then sorting the options by the number, and removing the votes count from the array. Here's my code
var sortedOptions = [];
for (let option of options) {
sortedOptions.push(option, option.votes);
}
sortedOptions.sort(function(a, b) {
})
I have been following this but I don't understand how the sort function is working and how to do it for my purposes.
Thanks for your help :)
EDIT: I tried doing the following code, however this was returning an object with 8 options and the object isn't sorted
sortedOptions.sort(function(a, b) {
return a.votes - b.votes;
})