Answers for "sort an array of class objects js"

2

sort array with objects

const list = [
  { color: 'white', size: 'XXL' },
  { color: 'red', size: 'XL' },
  { color: 'black', size: 'M' }
]

var sortedArray = list.sort((a, b) => (a.color > b.color) ? 1 : -1)

// Result:
//sortedArray:
//{ color: 'black', size: 'M' }
//{ color: 'red', size: 'XL' }
//{ color: 'white', size: 'XXL' }
Posted by: Guest on June-06-2021
5

sort array of objects javascript

list.sort((a, b) => (a.color > b.color) ? 1 : -1)
Posted by: Guest on July-23-2020

Code answers related to "sort an array of class objects js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language