最近我对JavaScript数组索引的本质有了一些认识。在探究过程中,我发现了以下内容(我正在使用Node.js解释模式):
var x=[];
x['a']='a';
console.log(x); // Yields [ a: 'a' ]
console.log(x.length); // yields 0 not 1
x[1]=1;
console.log(x); // Yields [ , 1, a: 'a' ]
console.log(x.length); // Yields 2 not 3 (one for empty 0 space, one for the occupied 1 space)
< p> a: 'a'
真的是看起来的样子 - 嵌入数组的对象属性 - 因此,在数组属性.length
中不计算吗? 这句话的意思是,一个包含对象属性的数组是否会在计算数组长度时将对象属性也计算在内。