Answers for "array sort string length"

5

sort array by string length javascript

function sortByLength(arr) {
   return arr.sort((x,y) => x.length - y.length);
}
Posted by: Guest on August-17-2020
0

js how to sort array by string length

(() => {
  let arr = ["HTML", "Go", "Ruby", "Python", "JavaScript", "CSS"];
  function sortByLength(arr) {
    return arr.sort((a, b) => a.length - b.length);
  }

  console.log(sortByLength(arr)); // => [ 'Go', 'CSS', 'HTML', 'Ruby', 'Python', 'JavaScript' ]
})();
Posted by: Guest on May-05-2022

Code answers related to "array sort string length"

Code answers related to "Javascript"

Browse Popular Code Answers by Language