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

我用循环输出数组元素 哪儿错了啊 - - 自己看不出来

<!DOCTYPE html>

<html>

<head>

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

<title>Array对象 </title>

<script type="text/javascript">

   function sortNum(a,b) {

       return b-a;


   }

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

var mystr=new array();

mystr=myarr.sort(sortNum);

var i=0;

for(i;i<mystr.length;i++;)

document.write(mystr[i]+"<br/>");

    

</script>

</head>

<body>

</body>

</html>


提问者:别说你没认真 2015-12-30 19:38

个回答

  • charlie111
    2015-12-30 19:56:02
    已采纳

    1. "var mystr=new array()"  ==>  "var mystr = new Array()"

    2. "for(i;i<mystr.length;i++;)"  ==> "for(i;i<mystr.length;i++)“


  • 产品经理不是经理
    2015-12-30 19:41:55

    var mystr=new array()这里错了