<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<script>
var arr=[0,1,2,5,10];
function func(a,b){
if(a>b){
return 1;
}
else if(a<b){
return -1;
}
else if(a==b){
return 0;
}
}
alert(arr.sort(func));//sort函数中引入比较函数
</script>
<body>
</body>
</html>
JavaScript数组中的sort函数
猜你喜欢
转载自blog.csdn.net/CWH0908/article/details/86770106
今日推荐
周排行