int 型数组排序
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> </head> <body> <script type="text/javascript"> function sortNumber(a,b){return a - b} var a = new Array(10,2,8); var b = a.sort(sortNumber); alert("排序为"+b+" "+"最大值是"+b[0]+" "+"最小值是"+b[b.length-1]) //alert(b.pop()); //最大值 //alert(b.shift());//最小值 </script> </body> </html>
字符串排序
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> </head> <body> <script type="text/javascript"> var a = new Array("a","c" , "b"); var b = a.sort(); alert(b) </script> </body> </html>
参考:http://www.w3school.com.cn/jsref/jsref_sort.asp