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

return a=b;与return 0;有什么区别?

<script type="text/javascript">

   function sortNum(a,b) {

     return 0;//输出结果为:80,16,50,6,100,1  

     return a=b;//输出结果为:1,100,6,50,16,80

   }

var myarr = new Array("80","16","50","6","100","1");

document.write(myarr.sort(sortNum));

</script>


提问者:慕容8154426 2017-10-02 10:39

个回答

  • qq_風中飘_0
    2017-10-02 12:57:05

    从结果上看:return 0;数组排序不变;

    return a=b;数组反转