sorting list by value js code example
Example 1: how to sort an array by value in javascript
//ascending order
arr.sort(function(a, b){return a-b});
arr.sort((a, b) => a - b);
//descending order
arr.sort(function(a, b){return b - a});
arr.sort((a, b) => b - a);
Example 2: sorting javascript list
list.sort((a, b) => (a.color > b.color) ? 1 : -1)