Skip to content

Instantly share code, notes, and snippets.

@jimmy89Li
Created March 30, 2019 11:14
Show Gist options
  • Save jimmy89Li/d51453a61be25efb14f936a8d840b69f to your computer and use it in GitHub Desktop.
Save jimmy89Li/d51453a61be25efb14f936a8d840b69f to your computer and use it in GitHub Desktop.
Sort objects by value
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