1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8" /> 5 <meta name="viewport" content="width=device-width, initial-scale=1"> 6 <title></title> 7 <script src="https://cdn.staticfile.org/jquery/3.3.1/jquery.js"></script> 8 </head> 9 <body> 10 <script> 11 var arr = [4, 3, 6, 5, 7, 2, 1]; 12 var arr1 = arr.sort(); 13 console.log(arr1[0]); 14 //输出结果[1,2,3,4,5,6,7] 15 var arr2 = arr.sort(function(a, b) { 16 return b - a; 17 }); 18 console.log(arr2); 19 //输出结果[7,6,5,4,3,2,1] 20 </script> 21 </body> 22 </html>