Summary of Array object method attributes in javacsript

Source: Internet
Author: User
This article describes in detail the methods of the Array object in javacsrip. the summary attributes mainly include three attributes: constructor; length; prototype;

Constructor: returns a reference to the array function that creates this object. Example: var arr = new Array (); arr. constructor = Array;

Length: sets or returns the number of elements in the array. Note: The length is always 1 larger than the last subscript of the array; set the length of the array: If the array is longer than the set length, the array will be truncated. If the array length is shorter than the set length, then, use undefined to add it later;

Prototype: enables you to add attributes and methods (prototype chain and property inheritance) to an object );

There are 12 commonly used methods:

Concat (arrayX); used to connect two or more arrays; (arrayX is required, the array to be linked) (create another new array without changing the original array );

Join ([Separator]); Put all elements in the array into a string. (Separator );

Pop (); Delete and return the last element of the array; (if the array is empty, pop () does not change the array and returns the undefined value .); (Advanced and later );

Push (); add one or more elements to the end of the array and return a new length. (Advanced and later );

Reverse (); used to reverse the order of elements in the array; (changes the original array without creating a new array .);

Shift (); Removes the first element from the array and returns the value of the first element. (Change the original array without creating a new array. );

Slice (start, [end]); returns the selected element from the existing array. (If start is a negative number, it specifies the position starting from the end of the array. That is to say,-1 refers to the last element,-2 refers to the second to last element, and so on .) (Start, end) === [start, end) before and after the package );

Sort ([function]); sorts the elements of the array. (By ascii code table); such as: (by number size: function sortNum (a, B) {return a-B });

Splice (index, number, [item]); index: location; number: quantity; item: Project to be replaced;

ToString (); convert the array to a string and return the result (same as the push effect without parameters );

Unshift (); add one or more elements to the beginning of the array and return a new length;

ValueOf (); returns the original value of the Array object.

The above is the detailed summary of Array object method attributes in javacsrip. For more information, see other related articles in the first PHP community!

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.