Category: >> JavaScript >> Easy Numeric Array Sorting Bookmark and Share

<< lastnext >>

Snippet Name: Easy Numeric Array Sorting

Description: The JavaScript Array object only sorts alphabetically, but this small function lets you sort an array numerically.

Also see:
» Find first non-numeric character i...
» Rounding numerical fields
» Strip all non-alphanumeric charact...

Comment: (none)

Author: CoderZone
Highlight Mode: JAVASCRIPT
Last Modified: December 01st, 2010

// handy function sorts numerically
Array.prototype.sortNum = function() {
  return this.sort(function (a,b) {return a-b;});
Add a comment 
DaveNov 18th, 2010 2:35pm
Very cool little bit of code!
© | users online: 5