Array Length:
The JavaScript array does not need to be set in length, it expands itself, and the array name. Length returns the number of elements
The code is as follows |
Copy Code |
var arr=new Array ("Saab", "Volvo", "BMW") Alert (arr.length)//can display array length |
The above is not our focus, focus on everyone look below.
1th:
The code is as follows |
Copy Code |
var lennon=array (); lennon["name"]= "Windy"; lennon["Year"]= "1989"; lennon["Living"]=true; alert (lennon.length); |
Results: Lennon.length was 0
Reason:
Adding an array element in the following way will not change the length of the array
Arr["a"]=3;
2nd:
The code is as follows |
Copy Code |
var foo2 = []; foo2[' 3 '] = 3; foo2[' age ' = 20; Debugger alert (foo2.length); |
Foo2.length is another 4.
All of the array objects that are not assigned are defined as undefined
JavaScript can automatically resize an array, an automatic sizing mechanism that makes it easier to get out of bounds arrays (out of bounds array) and harder to spot. So pay more attention to a similar situation.