A js array is special because
1. Its length attribute has some special behaviors:
1) when a new element is added to the List, its value is automatically updated;
2). Setting this attribute can expand or truncate the array.
2. JS arrays are also Array instances. Different Array methods can be called through them.
1 and 2 are unique features of JS arrays, but they are not the most basic features of defining an array. any object with a length attribute and corresponding non-negative integer attribute is called an array similar to an array.
Objects similar to arrays do not frequently appear, and they cannot call the array method or expect special behavior through the length attribute. 1) 2 ), however, you can still use code that traverses a real array to traverse them. in fact, many array algorithms are applicable to objects similar to arrays and real array objects, as long as you do not try to add elements to arrays or change the length attribute, you can treat objects like arrays as real arrays.
Create an array like this and traverse the array like this:
Var a = {};
Var I = 0;
// A small bug was introduced accidentally.
While (I ++ <10 ){
A [I] = I * I;
}
While (I <10 ){
A [I] = I * I;
I ++;
}
A. length = I;
Var total = 0;
For (var j = 0, len = a. length; j <len; j ++ ){
Total + = a [j];
}
In particular, the Arguments object in the function is an object similar to an array, and the DOM node list returned by getElementsByTagName () is also an object similar to an array.
By bill200711022