| ★ wanayoo — archive 1999 http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/length | Nouvelle recherche | Portail wanayoo |
An unsigned, 32-bit integer that specifies the number of elements in an array.
| Property of Array | |
| Implemented in: | JavaScript 1.1, NES 2.0
JavaScript 1.3: |
| ECMA Version: | ECMA-262 |
The value of the length property is an integer with a positive sign and a value less than 2 to the 32 power (232).
You can set the length property to truncate an array at any time. When you extend an array by changing its length property, the number of actual elements does not increase; for example, if you set length to 3 when it is currently 2, the array still contains only 2 elements.
In the following example the array numbers is iterated through by looking at the length property to see how many elements it has. Each value is then doubled.
var numbers = [1,2,3,4,5];
for (var i = 0; i < numbers.length; i++) {
numbers[i] *= 2;
}
// numbers is now [2,4,6,8,10];
Page last modified 21:02, 4 Aug 2007 by Mgjbot