Sort Arrays on Multiple Attributes
· ☕ 2 min read
You can quite easily sort arrays on multiple attributes using a simple Array.sort().
Consider this array -
1 2 3 4 5 6 const students = [ { name: "Rama", grade: 10, class: 5 }, { name: "Kris", grade: 7, class: 1 }, { name: "Jan", grade: 8, class: 5 }, { name: "Kris", grade: 5, class: 7 } ]; Sorting based on grade is easy.