CoderZone.org

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
Language: JAVASCRIPT
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!
© coderzone.org | users online: 5