I am making a game and I want to sort the scoreboard by the highest score and lowest time if the scores are the same. However I do not know how to do so, I have tried .sort() but I don't think it works for objects, please help thanks. Below shows the array with the information of users.
[
{ score: 2, userName: 'adam', time: '0:20' },
{ score: 4, userName: 'john', time: '0:45' },
{ score: 1, userName: 'kevin', time: '0:30' },
{ score: 8, userName: 'james', time: '0:20' },
]