Custom Numeric Comparison for the Array.Sort Method : Array « Language Basics « JavaScript DHTML

JavaScript DHTML
1. Ajax Layer
2. Data Type
3. Date Time
4. Development
5. Document
6. Event
7. Event onMethod
8. Form Control
9. GUI Components
10. HTML
11. Javascript Collections
12. Javascript Objects
13. Language Basics
14. Node Operation
15. Object Oriented
16. Page Components
17. Security
18. Style Layout
19. Table
20. Utilities
21. Window Browser
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
JavaScript DHTML » Language Basics » Array 
Custom Numeric Comparison for the Array.Sort Method

<HTML>
<HEAD>
<TITLE> 
Numeric comparisons 
</TITLE>
<HEAD>
<BODY>
<H1>
<SCRIPT
    function numSort(a,b){ 
       return a - b; 
    
    var numArray = new Array (59463121731
    document.write ("Original array: " + numArray)
    document.write ("<br>")
    document.write ("Default Sorted array: " + numArray.sort())
    document.write ("<br>")
    document.write ("Numerically sorted array: " 
       numArray.sort(numSort))
   </SCRIPT>
</H1>
</BODY>
</HTML>
           
       
Related examples in the same category
1. Demo all methods in Array
2. Assing array value inside function
3. Simple Array Demo
4. Array loop, find:Control array : Two dimension array
5. Reversing, Sorting, and Concatenating an Array
6. Case-Insensitive Comparison for the Array.Sort Method
7. Iterating Through a Sparse Array
8. Using Functions to Iterate Through an Array
9. Reading and Writing Array Elements
10. Array with a numeric parameter and assign data to it
11. A string array
12. Array - properties and methods:length, join, reverse, push,pop,shift
13. Array - sort()
14. Array - concat and slice
15. Array - splice
16. Methods and Properties of the Array Object
17. Displaying the Contents of an Array
18. Using the Array.join() Method
19. Using JavaScript Arrays
20. Extending the Length of an Array
21. An Array within an Array
22. Using the Methods of the Array object
23. Array.sort() Possibilities
24. Array.reverse() Method
25.  Array Concatenation
26. A Looping Array Lookup
27. A Simple Parallel Array Lookup
28. Adding a prototype Property
29. Two-Dimensional Array Work Around
30. Array definition and iteration
31. Reference an Array by index
32. URL Array
33. Array Utility functions
34. Dynamic array
w_ww___.j___ava__2__s_.c_om | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.