数组Array的使用

//数组
        //定义方式
            //空数组的定义方式
            /*var attr = new Array();
            var attr = [];
            var attr = new Array(3);*/
            //有值数组的定义
            //var attr = new Array("张三","李四","王五");
            //var attr =  ["张三","李四","王五"];
            //数组的遍历
                /*1.for遍历*/
                /*for (var i = 0; i < attr.length;i++) {
                    alert(attr[i]);
                }
                console.log(attr);
                0: "张三"
​
                1: "李四"
                ​
                2: "王五"
                ​
                length: 3*/
                
        //for-in的遍历
        /*for (var k in attr) {
            alert(attr[k]);
        }*/
        
        //定义一个空数组,对他进行赋值
        /*var aa = new Array();
        aa[0] = "茄子";
        aa[1] = "香蕉";
        aa[2] = "西瓜";
        aa[3] = "苹果";
        console.log(aa);*/
        
        //循环赋值
        /*for (var i= 0;i<= 5;i++) {
            attr[i] = i + 1;
        }
        attr = [1,2,3,4,5,6];
        console.log(attr);*/

 

posted @ 2018-04-09 11:01  淅沥沥丶下雨  阅读(67)  评论(0编辑  收藏  举报