JavaScript基础------(数组)
数组
一维数组
var fruits = ["apple","banana","pear"];
二维数组
var arr2 = new Array(); arr2["湖南"] = ["长沙","湘潭","株洲"]; arr2["广东"] = ["广州","深圳","珠海"]; document.write(arr2.length + "<br>"); //arr2.length = 0 document.write(arr2["湖南"].length + "<br>"); for(var i in arr2){ document.write("<h4>" + i + "</h4>"); for(var j in arr2[i]){ document.write(arr2[i][j] + " "); } }
字符串也可以做数组的索引,但是就不能使用for循环了,只可以用for-each循环。