Created
January 5, 2022 19:38
-
-
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
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
//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