Created
April 7, 2020 03:57
-
-
Save dqtweb/dffc0d141b6efe4cdc2760ff435866a6 to your computer and use it in GitHub Desktop.
javascript: sort array of objects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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