<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>数组排序</title>
<script>
//var arr=['dog','boy','cat','apple'];
//var arr=[3,12,67,9,23];
var arr=[3,12,67,9,23];
//方法一:
/*arr.sort(function (n1,n2)
{
if(n1>n2)
{
return 1;
}
else if(n1<n2)
{
return -1;
}
else
{
return 0;
}
});*/
//方法二:
arr.sort(function (n1,n2){
return n1-n2;
});
alert(arr);
</script>
</head>
<body>
</body>
</html>
数组排序
最新推荐文章于 2022-03-29 15:20:48 发布