In JavaScript, an array is a special object whose property name is a positive integer, and its length attribute changes as the array member increases or decreases, and some methods are inherited from the array constructor for array manipulation. And for an ordinary object, if all of its property names are positive integers and have the corresponding length attribute, then although the object is not created by the array constructor, it still renders an array of behaviors, in which case these objects are referred to as "class arrays objects." The following is a simple class array object:
Copy Code code as follows:
var o = {0:42, 1:52, 2:63, Length:3}
Console.log (o);
Unlike ordinary objects, the class array object has an attribute: The operation method of the array can be applied on the class array object. For example, in the ECMAScript 5 standard, you can combine the above object o into a string using the following methods:
Copy Code code as follows:
Console.log (Array.prototype.join.call (o));//"42,52,63"
You can also use the slice () method on a class array object to get a child array:
Copy Code code as follows:
Console.log (Array.prototype.slice.call (O, 1, 2));//[52]
In a browser environment, the document.getElementsByTagName () statement returns a class array object. In a function call, the arguments variable within the function code (which holds the incoming argument) is also an array object of the class.
In the ECMAScript 5 standard, a strings string is a read-only class Array object:
Copy Code code as follows:
var s = "History";
Console.log (S[3]);//t
Console.log (Array.prototype.join.call (S, ""));//h i s t o r y