Today, the sort function of the array can accept the custom comparison function, which is really a wonderful thing. In this way, it is very easy to sort (numbers within the range. Var myArray = [-80,-13.888,-10,-9.6,-9.4,-5.823,-7.999, 312,]; iJs. put (myArray. sort (function (a, B) {return a-B}); debugging information:-80,-13.888,-10,-9.6,-9.4, 3, 5.823, 7.999, 20, 22, 55,312 If You Want To descending order, change a-B to B-a: var myArray = [-80,-13.888,-10,-9.6, -9.4,-5.823, 7.999, 55,312, 0,]; iJs. put (myArray. sort (function (a, B) {return B-a}); // debug information for B-a: 7.999, 5.823, -1,-9.4,-9.6 ,-10,-13.888,-80 construct the function that returns the comparison function to achieve a more flexible purpose. For this reason, I have written a common sorting function for one-dimensional and two-dimensional arrays as follows (for example, for production, it is best to test it again): // ratio of the same type, the ratio type is different from the type specified by the first parameter of option. The ratio type is specified by the second parameter of option. // if it is an object or an array, specify attributes by name or participate in sorting by elements. // if the results are the same, sort the values according to the rules specified by secondby. var by = function (name, option, secondby) {return function (o, p) {var a, B; var sign = 1; // adjust the order var r; // Save the returned value // if it is an object or an array, if (o & typeof o = 'object') {a = o [name];} else {a = o ;} if (p & typeof p = 'object') {B = p [name];} e Lse {B = p;} if (typeof a = typeof B) {// switch (option [0]) is specified by the first parameter of option. {case "desc": sign = 1; break; case "asc": sign =-1; break; default: sign = 1; // default} else {// type is different than type a = typeof a; B = typeof B; // switch (option [1]) {case "desc": sign = 1; break; case "asc": sign =-1; break; default: sign = 1; // default} if (a = B) {r = typeof secondby = "function "? Secondby (o, p): 0; // recursion supports sorting of multiple parameters} else if (a <B) {r = 1 * sign ;} else {r =-1 * sign;} return r ;}// determine whether the array var is_array = function (value) {return value & // The value typeof value = "object" & // typeof indicates that the object typeof value type is used. length = "number" & // The length attribute is of the number type typeof value. splice = "function" & // method of splice available! (Value. propertyIsEnumerable ("length") // length is an attribute that cannot be enumerated} // outputs a two-dimensional array var puts = function (myObj) {for (var I = 0; I <myObj. length; I + = 1) {var tmp = ""; if (is_array (myObj [I]) {for (var j = 0; j <myObj [I]. length; j + = 1) {tmp = tmp + myObj [I] [j] + "," ;}} else {for (name in myObj [I]) {tmp = tmp + name + ":" + myObj [I] [name] + "," ;}} iJs. put (tmp) ;}}var myArray = new Array (); // Example 1 myArray = [{"a": 1, "B": 1, "c ": 1 },{ "a": 3, "B": 3, "c": 1 },{ "a": 3, "B": 4, "c ": 1 },{ "a": 3, "B": 1, "c": 1 },{ "a": 2, "B": 1, "c ": 2}, {"a": 2, "B": 1, "c": 1},]; myArray = myArray. sort (by ("a", ["asc"], by ("B", [], by ("c", ["asc"]); puts (myArray); // Example 2 myArray = [[, 1], [, 1], [, 1], [, 1, 2], [2, 1, 1]; myArray = myArray. sort (by (0, ["asc"], by (1, [], by (2, ["asc"]); puts (myArray ); // Example 3 myArray = [-80,-13.888,-10,-9.6,-9.4,-5.823,-7.999, 55,312,]; myArray = myArray. sort (by (null, ["asc"]); iJs. put (""); iJs. put (myArray); debugging information: a: 1, B: 1, c: 1, a: 2, B: 1, c: 1, a: 2, B: 1, c: 2, a: 3, B: 4, c: 1, a: 3, B: 3, c: 1, a: 3, B: 1, c: 1, 13.888, 1, 9.6, 1, 9.4, 2, 3, 3, 3, 1, 3, 3, 1, 1,-80,-,-10, -5.823, 7.999, 55,312