Skip to content

Instantly share code, notes, and snippets.

@richleach
Created January 5, 2022 19:38
Show Gist options
  • Save richleach/d5fd612f97046fdd9f03806c7520b849 to your computer and use it in GitHub Desktop.
Save richleach/d5fd612f97046fdd9f03806c7520b849 to your computer and use it in GitHub Desktop.
Loop over JSON and sort results by one of the JSON name elements
//array of objects
const myItems = [{"name": "eggs", "price": 1},{"name": "coffee", "price": 9.99}, {"name": "rich", "price": 4.04}]
//If you want to sort myItems by price.
const revised = myItems.sort((function(a,b){
return a.price - b.price
}))
console.log(revised);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment