Array Method Summary

Source: Internet
Author: User

Slice: Slice --Returns a new array--copy array: Arr.slice (0)
Arrayobject.slice (start,end): slices
var arr= [1,2,3,4]arr.slice (1,3); // [2, 3]arr.slice (0); // [1, 2, 3, 4] copies an array, or the loop element is copied. The copy array is a copy and B===a is false. B=a is a pointer, B===a is true

Concat: Concatenate two or more arrays, return a new array, copy array: Arr.concat ()

Concat () joins two or more arrays and returns the result.

Arrayobject.concat (Arrayx,arrayx,......, Arrayx)

var arr=[1,2];arr.concat (3);//[1, 2, 3]arr.concat ([3,4]),//[1, 2, 3, 4], take out the elements of the array arr.concat ([[[6,7],[8,9]]);//[1, 2, array[2]0:61:7length:2__proto__: array[0], array[2]0:81:9length:2__proto__: array[0]]//out is just the elements in the first layer of the array OH

Change the original array (add return length, delete deleted elements):

  Reverse: Reverses the order of elements in the original array (implemented by sort), returns the original array after the change

  Sort: Sorts the elements of the original array, and returns the original array after the change

var arr=[1,3,2];//undefinedarr//[1, 3, 2]arr.sort (function (A, b) {return b-a})//[3, 2, 1]arr.sort (function (A, b) {return A-B})//[1, 2, 3]

  Push: Returns the array length by adding an element to the end of the array   

Arr.push ([])//5arr//[1, 2, 3, "a", array[0]]

  Pop: Delete end element and return end element

Arr.pop ()//[]arr//[1, 2, 3, "a"]

 Shift: Delete an element and returns the value of the first element

Arr.shift ()//1arr//[2, 3, "a"]

 Unshift: Adds an element to the beginning of the array and returns the new length

Arr.unshift ("B")//4arr//["B", 2, 3, "a"]

 Splice to/from an array, and returns the deleted item

Arrayobject.splice (index,howmany,item1,....., ItemX)

Parameters Description
Index Necessary. 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 Necessary. 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.
arr//["B", 2, 3, "a"]arr.splice (2,0, "William")//[]arr//["B", 2, "William", 3, "a"]

  

Array Method Summary

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.