Introduction to class array objects in JavaScript _ javascript skills

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.