Answers for "alphabetize site:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array"

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

Code answers related to "alphabetize site:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array"

Browse Popular Code Answers by Language