Answers for "javascript sort when to use - and when to use >"

13

javascript sort

var names = ["Peter", "Emma", "Jack", "Mia", "Eric"];
names.sort(); // ["Emma", "Eric", "Jack", "Mia", "Peter"]

var objs = [
  {name: "Peter", age: 35},
  {name: "Emma", age: 21},
  {name: "Jack", age: 53}
];

objs.sort(function(a, b) {
  return a.age - b.age;
}); // Sort by age (lowest first)
Posted by: Guest on May-21-2020
-1

javascript sort by id

elems.sort((a, b) => a.id - b.id);
Posted by: Guest on June-17-2020

Code answers related to "javascript sort when to use - and when to use >"

Browse Popular Code Answers by Language