how to sort an array of strings by 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 sorting array string by len
array.sort(function(a, b){return b.length - a.length});