sort array length javascript code example
Example 1: sort array by string length javascript
function sortByLength(arr) {
return arr.sort((x,y) => x.length - y.length);
}
Example 2: javascript sort by id
elems.sort((a, b) => a.id - b.id);
function sortByLength(arr) {
return arr.sort((x,y) => x.length - y.length);
}
elems.sort((a, b) => a.id - b.id);