sort()分类的判断到底根据是a-b>0,<0来执行还是>=1,<=-1,<1&&>-1执行的?

<!DOCTYPE html>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Array对象 </title>

<script type="text/javascript">

   function sort1num(a,b) {

        return b-a;

   }

var myarr = new Array("80","16","16.5","16.2","100","1");

myarr.sort(sort1num);

document.write(myarr);

</script>

</head>

<body>

</body>

</html>


fanaiwen
浏览 1684回答 2
2回答

OmeKrystal

可以看看这个例子:JavaScript sort() 方法sort()分类的判断的是a-b>0,<0,=0
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript