问答详情
源自:7-22 数组排序sort()

调用sortNum不应该是sortNum()吗?

<script type="text/javascript">
  function sortNum(a,b) {
  return a - b;
 //升序,如降序,把“a - b”该成“b - a”
}
 var myarr = new Array("80","16","50","6","100","1");
  document.write(myarr + "<br>");
  document.write(myarr.sort(sortNum));
</script>


提问者:慕田峪347267 2019-06-21 13:31

个回答