js数组

JavaScript的数组

它的长度是动态改变的,里面可以放任意类型的元素,在内存中不连续(强类型中的集合)。

定义方式:

            var arr = new Array(); 

 

            var arr = [];

             arr[]

实例var a=[1,2,3,[4]];

           alert(a[3][0]);

赋值方式

arr[0]="aaa";

.push("ccc");

 

循环与数组的结合

实例

1.      var a =["a","b",3];

                     a.push("aaa");

              console.log(a);

2. var a =["a","b",3];

                     a[3]="111"

              console.log(a);

Json数据

遍历

for(var a in 遍历的值){

     

}

 

实例1

Var a=[1,2,3,4];

                              alert(a.length); (英文)长度的意思

 

var a=[1,2,3,4]

              for(var i in a){

              }alert(i)长度03

 

json有key值,书写的格式和数组有差别

 “var sheng ={

                            "shandongsheng":"山东",

                                   "heilongjiang":"黑龙江",

                            }

               var shi ={

                               "山东":{

                                      qingdiao:"青岛",

                                      jinan:"济南",

                                      zibo:"淄博"},”}

字符串“shangdong”:”山东“字符串

Json没有。Push

实例

   var a = [];数组的内容

                         var d=0;

                                for(var b=0;b<10;b++){

                                       a[b]=[];

                                       for(var c =0;c<=9;c++){

                                             d=d+1;

                                             a[b][c]=d;

                                       }

                         }

                                            console.log(a);                                               

  console.log(shi[sheng["shandongsheng"]]['zibo'])

书写格式a[“a”][s]

           字符串

var a={

                可以不写引号1:123,可以不写引号

                'b':"wangyi",

         }

         alert(a["1"]);

字符串必须加引号“”

posted @ 2019-01-04 11:18  小白WY  阅读(111)  评论(0编辑  收藏  举报