Languages
[Edit]
EN

JavaScript - sort array based on length of each element

0 points
Created by:
Kadeem-Craig
516

In this article, we would like to show you how to sort array based length of each element in JavaScript.

Quick solution (ES6):

 

1. Ascending order

Edit

In this example, we sort the elements in the array from the shortest to the longest ones.

2. Descending order

Edit

In this example, we sort the elements in the array from the longest to the shortest ones.

 

References

Edit
  1. Array.prototype.sort() - JavaScript | MDN

Alternative titles

  1. JavaScript - sort array of strings based on length of each item
  2. JavaScript - sort array by elements length
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join