sort array of objects by key typescript code example
Example 1: typescript sort array of objects
const list = [
{ color: 'white', size: 'XXL' },
{ color: 'red', size: 'XL' },
{ color: 'black', size: 'M' }
]
list.sort((a, b) => (a.color > b.color) ? 1 : -1)
Example 2: sort array of objects javascript by key value
myArray.sort(function(a, b) {
return a.distance - b.distance;
});