Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

sort array by string length javascript

function sortByLength(arr) {
   return arr.sort((x,y) => x.length - y.length);
}
Comment

javascript sorting array string by len


array.sort(function(a, b){return b.length - a.length});
Comment

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' ]
})();
Comment

PREVIOUS NEXT
Code Example
Javascript :: set attribute checked jquery 
Javascript :: explode in jquery 
Javascript :: javascript check if function exists 
Javascript :: angular.json bootstrap path 
Javascript :: disable all element in div angular 12 
Javascript :: javascript clear div 
Javascript :: listing dir by nodejs 
Javascript :: prevent default window on right click menu 
Javascript :: settimeout in angular 
Javascript :: how to get the first key in a n object in javascript 
Javascript :: how to link javascript to html and css 
Javascript :: on radio button change jquery 
Javascript :: javascript confirm yes no 
Javascript :: how to store objects in localstorage 
Javascript :: js vanilla dom ready 
Javascript :: hr react 
Javascript :: ready function jquery 
Javascript :: creat react app 
Javascript :: bootstrap show modal jquery 
Javascript :: javascript get element height and width 
Javascript :: javascript function to format phone number 
Javascript :: jquery set title attribute 
Javascript :: jquery replace element 
Javascript :: math.random javascript 
Javascript :: javascript change comma to dot 
Javascript :: javascript padstart 
Javascript :: bootbox cdn 
Javascript :: node express server static files 
Javascript :: javascript split get last element 
Javascript :: how to add attribute in jquery 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =