This article mainly introduces the class Array objects in JavaScript. an object is not created by the Array constructor and still presents the behavior of an Array. in this case, these objects are called "class array objects". For more information, see JavaScript. an array is a special object whose property name is a positive integer, the length attribute changes with the increase or decrease of Array members, and inherits some methods used for Array operations from the Array constructor. For a common object, if all its property names are positive integers and corresponding length attributes exist, although this object is not created by the Array constructor, it still presents the behavior of arrays. in this case, these objects are called "class array objects ". The following is a simple array object of classes:
The code is as follows:
Var o = {, 2: 63, length: 3}
Console. log (o );
Unlike normal objects, a class array object has a feature that can be used to operate arrays on class array objects. For example, in the ECMAScript 5 standard, you can use the following method to merge the above object o into a string:
The code is as follows:
Console. log (Array. prototype. join. call (o); // "42,52, 63"
You can also use the slice () method to obtain the sub-array on the class array object:
The code is as follows:
Console. log (Array. prototype. slice. call (o, 1, 2); // [52]
In the browser environment, the document. getElementsByTagName () statement returns an array object of classes. In a function call, the arguments variable in the function code (storing input parameters) is also an array object of classes.
In the ECMAScript 5 standard, string is a read-only array object:
The code is as follows:
Var s = "History ";
Console. log (s [3]); // t
Console. log (Array. prototype. join. call (s, ""); // H I s t o r y