毕业论文开发语言企业开发JAVA技术.NET技术WEB开发Linux/Unix数据库技术Windows平台移动平台嵌入式论文范文英语论文
您现在的位置: 毕业论文 >> WEB开发 >> 正文

从一个已有数组中向另外一个空白数组添加元素

更新时间:2013-5-12:  来源:毕业论文

从一个已有数组中向另外一个空白数组添加元素

var adressTable=new Array("image/01.png","image/02.png","image/03.png","image/04.png","image/05.png","image/06.png","image/07.png","image/08.png","image/09.png","image/10.png","image/11.png","image/12.png","image/13.png","image/14.png","image/15.png"); var newArray=new Array();    getNum(newArray,adressTable); alert(newArray[0]); function getNum(a,b){     while(a.length<=15){     var index = Math.floor(Math.random() * 15);     for(j=0;j<a.length;j++){     if(a[j]==b[index])       {         break;        }     else       {     var e=b[index];     a.push(e);     n++;       }     }   }     return a;       }
这是想无序添加么?

因为你一开始a.length=0,所以for循环一直不会进else里面

所以a.length一直等于0 毕业论文 

都没执行for循环里面的内容,判断下当a.length==0时的添加数组元素

var adressTable=new Array("image/01.png","image/02.png","image/03.png","image/04.png","image/05.png","image/06.png"
,"image/07.png","image/08.png","image/09.png","image/10.png","image/11.png","image/12.png","image/13.png","image/14.png","image/15.png");
var newArray=new Array();
getNum(newArray,adressTable);
alert(newArray[0]);
function getNum(a,b){
    while(a.length<=15){
        var index = Math.floor(Math.random() * 15);
        var ft=false;
         for(j=0;j<a.length;j++){
            if(a[j]==b[index]){
                ft=true;
                break;
             }
        }
        if(!ft){
            var e=b[index];
            a.push(e);
            n++;
        }
    }
    return a;  
}

设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©youerw.com 优尔论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。