The javascript sorting function supports numerical sorting and javascript sorting.
Use the javascript sorting function to sort numbers.
<Script> function SortNumber (obj, func) // defines the universal sorting function {// parameter verification. if the first parameter is not an array or the second parameter is not a function, an exception is thrown if (! (Obj instanceof Array) |! (Func instanceof Function) {var e = new Error (); // generate Error message e. number = 100000; // defines the error code e. message = "invalid parameter"; // error description throw e; // throw an exception} for (n in obj) // start sorting {for (m in obj) {if (func (obj [n], obj [m]) // use the callback function for sorting. The rules are set by the user {var tmp = obj [n]; // create a temporary variable obj [n] = obj [m]; // exchange data obj [m] = tmp ;}} return obj; // return the sorted array} function greatThan (arg1, arg2) // callback function, user-defined sorting rule {return arg1 <arg2 ;} try {var numAry = new Array (, 9); // generate an Array of documents. write ("<li> before sorting:" + numAry); // output the array SortNumber (numAry, greatThan) Before sorting; // call the sorting function document. write ("<li> after sorting:" + numAry); // output the sorted array} catch (e) {alert (e. number + ":" + e. message) ;}</script>
The above is all the content of this article. I hope you will like it.