Created
March 30, 2019 11:14
-
-
Save jimmy89Li/d51453a61be25efb14f936a8d840b69f to your computer and use it in GitHub Desktop.
Sort objects by value
This file contains 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
const list = [ | |
{ key: 7, val: "amazon" }, | |
{ key: 3, val: "msn" }, | |
{ key: 5, val: "github" }, | |
{ key: 1, val: "google" }, | |
{ key: 4, val: "stackoverflow" }, | |
{ key: 6, val: "jsfiddle" }, | |
{ key: 2, val: "yahoo" }, | |
{ key: 8, val: "ebay" } | |
]; | |
const sorted = list.sort(function(a, b){ | |
return a.val.localeCompare( b.val ); | |
}); | |
console.log(sorted); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment