Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

sort from the key value js

var masterList = [
    { key: 1, val: "google" },
    { key: 2, val: "yahoo" },
    { key: 3, val: "msn" },
    { key: 4, val: "stackoverflow" },
    { key: 5, val: "github" },
    { key: 6, val: "jsfiddle" },
    { key: 7, val: "amazon" },
    { key: 8, val: "ebay" }
];

masterList.sort((a,b)=> (a.val < b.val ? 1 : -1)) //For Decending

masterList.sort((a,b)=> (a.val > b.val ? 1 : -1)) //For Ascending

console.log( masterList );
 
PREVIOUS NEXT
Tagged: #sort #key #js
ADD COMMENT
Topic
Name
6+4 =