sort object in arrays js code example
Example 1: sort array of objects javascript
list.sort((a, b) => (a.color > b.color) ? 1 : -1)
Example 2: javascript sort object by key
function sortObjectByKeys(o) {
return Object.keys(o).sort().reduce((r, k) => (r[k] = o[k], r), {});
}
var unsorted = {"c":"crane","b":"boy","a":"ant"};
var sorted=sortObjectByKeys(unsorted); //{a: "ant", b: "boy", c: "crane"}