Skip to content

Instantly share code, notes, and snippets.

@thomasxbanks
Created March 1, 2017 08:59
Show Gist options
  • Select an option

  • Save thomasxbanks/9fdd34e6c166e258784036f667ce967b to your computer and use it in GitHub Desktop.

Select an option

Save thomasxbanks/9fdd34e6c166e258784036f667ce967b to your computer and use it in GitHub Desktop.
Sort an array of objects
'use strict'
let person = [
{ name: "Person 1", age: 28 },
{ name: "Person 2", age: 22 },
{ name: "Person 3", age: 26 }
]
person.sort(function(obj1, obj2) {
// Ascending: first age less than the previous
return obj1.age - obj2.age
})
console.log(person)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment