To access the elements of the array we can use this length property to loop through. Please note that first element of an array starts from 0 so array_name is the second element of the array where as array_name is the first element of the array. Same way the last element of the array is the total size of the array minus one.
Returns the length of the array.
The value of the length property is an integer with a positive sign and a value less than 2 to 32nd power (232).
var namelistX = new Array(4294967296); //2 to the 32nd power = 4294967296 var namelistZ = new Array(-100) //negative sign console.log(namelistX.length); //Error: array length is Invalid console.log(namelistZ.length); //Error: array length is Invalid var namelistY = ; namelistY.length = Math.pow(2,32)-1; //set array of length less than 2 to the 32nd power console.log(namelistY.length);
You can set the length property to shorten an array at any time.
When you expand an array by changing its length property, the number of real elements increases;
For example, if you currently set length 3 to be 2, the array now includes 3 elements, which makes the third element a non-moveable empty slot.
Property attributes of ‘Array.Length’
- Writable: If this attribute is set to false, the value of the property cannot be changed.
- Configurable: If this attribute is set to false, then any attempt to delete the property or change its properties (Writable,Configurable or Enumerable ) will fail.
- Enumerable : If this attribute is set to true, the property will be iterated over during for..in loops.