A summary of some common methods of array arrays in JS

Source: Internet
Author: User

The var list = new Array () is the code that we often write in JS, which summarizes what methods the objects of the AHA Array have today.

List[0] = 0;

LIST[1] = 1;

LIST[2] = 2;

Or declare this: var list = [0,1,2]

1 shift ()T: Deletes the first element of the array, returning the deleted value. This is 0.

2 unshift (3,4): Returns the length of the array by loading the arguments in front of the array. Now list: Medium is 3,4,0,1,2

3pop (): Deletes the last element of the array, returning the deleted value. This is 2.

4push (3): Loads the parameter to the end of the array, returns the length of the array, and now in list: 0,1,2,3

5concat (3,4): The two arrays are stitched together.

6splice (start,deletecount,val1,val2,...): Deletes the DeleteCount entry starting from the start position and inserts the Val1,val2 from that position,...

Reverse: Reverse the array
var a = [1,2,3,4,5];
var B = A.reverse (); a:[5,4,3,2,1] b:[5,4,3,2,1]

sort (orderfunction): Sorts the array by the specified parameters
var a = [1,2,3,4,5];
var B = A.sort (); a:[1,2,3,4,5] b:[1,2,3,4,5]

Slice (start,end): Returns a new array that consists of the entries from the original array that specify the starting subscript to the end subscript
var a = [1,2,3,4,5];
var B = a.slice (2,5); a:[1,2,3,4,5] b:[3,4,5]

Join (separator): Sets the element group of the array as a string, separator as a delimiter, and the default comma delimiter if omitted.
var a = [1,2,3,4,5];
var B = A.join ("|"); a:[1,2,3,4,5] B: "1|2|3|4|5"

A summary of some common methods of array arrays in JS

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.