Answers for "reacrete array by object order"

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 based on another array

arr.sort((a, b) =>{  
	return sortingArray.indexOf(a) - sortingArray.indexOf(b);
});
Posted by: Guest on November-28-2020

Code answers related to "reacrete array by object order"

Code answers related to "Javascript"

Browse Popular Code Answers by Language