Sort An Array By Element Length In Javascript

Posted by Weston Ganger on December 31, 2015

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:

Posted in Javascript and Tagged with javascript array sort 

Want me to help develop your next project or application?

Contact Us

Specializing in Ruby-on-Rails, Javascript, Multi-Platform Electron Desktop Apps and Hybrid Cordova Mobile Apps.

Recommended Posts