When you access a property that does not exist in the object, javascript will return undefined.
However, undefined can be assigned manually, which will be handled as described in ECMAScript Language Specification.
Assigning a property that does not exist before will result in array length increment, if the property name is an array index and the index is out of bound.
Assigning to length property will result in array length changing as well.
Otherwise, it will be handled as normal object property.
实名反对以上所有答案
Arrayis anObjectWhen you access a property that does not exist in the object, javascript will return
undefined.However,
undefinedcan be assigned manually, which will be handled as described in ECMAScript Language Specification.Assigning a property that does not exist before will result in array length increment, if the property name is an array index and the index is out of bound.
Assigning to
lengthproperty will result in array length changing as well.Otherwise, it will be handled as normal object property.
是的,只有赋值了之后才会改变数组长度的。
前者,arr[34]你并没有给他赋值,只是去查找,不存在,所以undefined
后者,你为arr[34]=34,赋值了,从arr[4]到arr[33]会填充值为undefined,所以长变为35
你说错了。
arr[34]的值还是没有。Arrray 类型你对没有初始化的值访问的时候,他会返回undefined,但是他并不意味着这里已经存在值,所以你访问length的时候,并不会显示,但是只要你对某项初始化,那么他就会反应到length上