JavaScript Array collation

Source: Internet
Author: User
Tags javascript array

Will affect the original array.
1, Shift (): Deletes the first element of the array, returning the deleted value.
2, Unshift (3,4): The parameter is loaded in front of the array, returning the length of the array.
3. Pop (): Deletes the last element of the array, returning the deleted value.
4, Push (3): Loads the parameter to the end of the array and returns the length of the array.
5, Splice (Start,deletecountnum,val1,val2,...) : Deletes the Deletecountnum entry starting from the start position and inserts the Val1,val2 from that position,..., returns the deleted value
6, reverse (): Reverse the array, return the reverse order of the array
7. Sort (orderfunction): Sorts the array by the specified parameters

If you want to sort by numeric size
A.sort (function(b) {return A- b;});


does not affect the original array.
1. Concat (arr): Two arrays are stitched together.
2, 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
3.join (separator): Sets the element group of the array as a string, separator as a delimiter, or by default with a comma delimiter, which receives only one argument: the delimiter. Returns the separated value
4.split (separator): Separates a string into an array, separator as a delimiter, returns the array that is composed
5.indexOf and LastIndexOf

IndexOf (): Receives two parameters: the subparagraphs (optional) to find indicates the index at which to find the starting point. Where the starting position of the array (position 0) is searched backwards
LastIndexOf (): Receives two parameters: the subparagraphs (optional) to find indicates the index at which to find the starting point. Where you start looking forward from the end of the array.

6.forEach

Arr.foreach (function+ "|" + Index + "|" + a);});

7.map

Arr.map (function(item) {return item*item});

8.filter

Arr.filter (function(x, index) {return index% 5 = = = 0 && x >= 4;});

9.every and some

Arr.every (function(x) {return x > 0});

10.reduce and Reduceright

JavaScript Array collation

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.