I have the following array of objects:
const items = [
{ name: "Different Item", amount: 100, matches: 2 },
{ name: "Different Item", amount: 100, matches: 2 },
{ name: "An Item", amount: 100, matches: 1 },
{ name: "Different Item", amount: 30, matches: 2 }
]
I need to sort these by matches and amount, so the final result looks like this:
[
{ name: "Different Item", amount: 100, matches: 2 },
{ name: "Different Item", amount: 100, matches: 2 },
{ name: "Different Item", amount: 30, matches: 2 },
{ name: "An Item", amount: 100, matches: 1 }
]
The first priority is to sort everything by matches, and then within those, I need to sort them by amount. I know I can sort by just matches or just amount like so:
items.sort((a, b) => a.matches - b.matches);
But how can I sort by both?