js数组的奇异特点

lenth不计算元素的个数

也就是说空缺也会数

['a','b'].length//2
['a',,'b'].length//3

forEach不遍历空缺

['a',,'b'].forEach(function(x)
                   {
    console.log(x)})// a b

清空数组

var arr=['a','b']
arr.length=0//0
arr//[]

删除数组不要留洞

js数组的奇异特点_第1张图片
image.png

你可能感兴趣的:(js数组的奇异特点)