数组length属性的一些特性

~~·数组的length属性是可读写的

var colors = ["blue","red","green"];
colors.length = 2;
alert(colors[2]);//undefined 移除

colors.length = 8;
alert(colors[6]);//undefined 新增

colors[99] = "black";
alert(colors.length);//100
小结:数组的length属性不是只读的。将length的值设置小于当前长度,会删除后面的项;设置大于当前长度,会新增项,新增项的值默认为undefined。
当把一个值放在超出数组大小的位置时,数组就会重新计算其长度值,即长度值等于最后一项的索引加1.

原文地址:https://www.cnblogs.com/stephenykk/p/3175086.html