JavaScript ES6 Array properties, methods, and their extensions

Source: Internet
Author: User

1. Create an array:

The first is the use of the Array constructor:

var New // create an empty array var New // create an array with 20 items var New // create an array with 3 strings

The second basic approach is to use the array literal notation:

var // create an empty array var // create an array with 1 items var // create an array with 3 strings

2. Array properties:
Constructorlengthprototype

3. Methods of arrays:
Join () push () and pop () shift () and unshift () sort () reverse () concat () Slice () splice () indexOf () and LastIndexOf () (ES5 new) ForEach () (ES5 New) map () (ES5 new) filter () (ES5 New) every () (ES5 New) Some () (ES5 Add) reduce () and reduceright (ES5 new)

4. Array, string conversion
Json.parse (' [[+]] ') [0]===1eval (//  should avoid using evaljson.stringify ([]) = = = = "[]"

5. Adding elements to an array
Let arr = []arr.unshift (//// array at the beginning of the add , returns the added element // array End added, returns the added element arr[ Arr.length]  // the method of replacing and adding  //  adding, replacing, and deleting array members at the specified location index is required. An integer that specifies the location of the Add/remove item, using a negative number to specify the position from the end of the array. Howmany    required. The number of items to delete. If set to 0, the item is not deleted. Item1, ..., ItemX optional    . Adds a new item to the array. 

6. Array Delete element

// removes the first element and returns the element value, and the elements in the array are automatically moved forward Arrobj.shift (); Arrobj.splice ()

7. Interception and merger

Returns a portion of the array as an array, noting that the element of end is not included, and if the end is omitted, all elements after start are copied

Concatenate multiple arrays (which can also be strings, or a mixture of arrays and strings) into an array, returning a new, well-connected array

8. Deep copy of the array

Returns a copy array of the array, note that it is a new array, not a pointer to the

Returns a copy array of the array, note that it is a new array, not a pointer to the

Because the array is a reference data type, the direct assignment does not reach the true implementation of the copy, the address reference, what we need is a deep copy.

9. Array sorting

Sort the array elements, returning the address of the arrays

10. Merging into characters
Arrobj.join ()

JavaScript ES6 Array properties, methods, and their extensions

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.