<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script> var arr=[12, 8, 99, 19, 112]; arr.sort(function (n1, n2){ if(n1<n2) { return -1; } else if(n1>n2) { return 1; } else { return 0; } }); alert(arr); </script> </head> <body> </body> </html>
时间: 2024-10-08 10:13:28