Answers for "sort array of objects typescript"

5

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)
Posted by: Guest on June-15-2020
15

sort by object property javascript

let list = [
  {
      name: "world"
  },
  {
      name: "hello",
  },
];

// This doesn't account for if names are the same between objects
let x = list.sort((a, b) => (a.name > b.name ? 1 : -1));

console.log(x);

/*
[
  {
      name: "hello",
  },
  {
      name: "world"
  },
];
*/
Posted by: Guest on August-23-2020
1

sort array of objects javascript by key value

myArray.sort(function(a, b) {
    return a.distance - b.distance;
});
Posted by: Guest on November-26-2020

Code answers related to "sort array of objects typescript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language