I am currently looking for a software/web development job preferably as a Rails-based developer.
Please email me at weston@westonganger.com. Thanks in advance for any leads!

Sort An Array By Element Length In Javascript

Posted by Weston Ganger

I had a string array that I wanted to sort based on word length.

Here’s a simple example using Array’s sort function.

var my_array = ['my','super','awesome','list','of','strings'];

  return a.length - b.length; //ASC, For Descending order use: b - a

// => ['my','of','list','super','awesome','strings']

Related External Links:

Article Topic:Software Development - Javascript

Date:December 31, 2015

Recommended Posts