Introduction to class array objects in JavaScript, javascript Array

Source: Internet
Author: User
Tags javascript array

Introduction to class array objects in JavaScript, javascript Array

In JavaScript, an array is a special object. Its property name is a positive integer and Its length attribute changes with the increase or decrease of array members, at the same time, some methods used for Array Operations are inherited 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:
Copy codeThe 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:
Copy codeThe 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:
Copy codeThe 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:
Copy codeThe 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

Related Article

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.