var a = new array();
var b = new array(8);
var c = new array("first", "second","third");
或者数组直接量:
var d = ["first", "second","third"];
下面看一下,在数组后面增加一个元素
var myarray = [];
myarray[myarray.length] = 'new element';
数组的长度
array只有一个属性,就是length,length表示的是数组所占内存空间的数目,而不仅仅是数组中元素的个数,在刚才定义的数组中,b.length的值为8
<script>
var a = new array("first", "second","third")
a[48] = "12"
document.write(a.length)
//显示的结果是49
</script>
下面来看看修改数组长度实例
var myarray = [1,2,3];
myarray.length // 3
myarray.length = 2; //delete the last element
myarray.length = 20 // add 18 elements to the array; theelements have the undefined value.
新闻热点
疑难解答