Skip to content

Instantly share code, notes, and snippets.

@dqtweb
Created April 7, 2020 03:57
Show Gist options
  • Save dqtweb/dffc0d141b6efe4cdc2760ff435866a6 to your computer and use it in GitHub Desktop.
Save dqtweb/dffc0d141b6efe4cdc2760ff435866a6 to your computer and use it in GitHub Desktop.
javascript: sort array of objects
// example, we want to sort list of objects based on an object's attribute. ex: "age"
var peopleList = [{"name": "Laura", "age":5}, {"name": "Peppa", "age": 40}, {"name": "Josh", "age":22}];
var comparision = function(a, b) { return a.age > b.age ? 1 : -1; };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment