JS Basics-Common Array manipulation methods

Source: Internet
Author: User

1, Slice ()

Method: Arrayobject.slice (Start,end)
Return value: Returns a new array containing elements from start to end (excluding the element) in the Arrayobject.

2, Splice ()

Method:Array. Splice (index,howmany,item1,.....,ItemX)

index: Where to add/remove elements from

howmany: How many elements should be removed. Must be a number, but it can be "0". If this parameter is not specified, all elements from index start to the end of the original array are deleted.

Item: Optional. The new element to add to the array.

The return value: the Splice () method modifies the array directly, and if the element is removed from the Arrayobject, it is returned as a set of elements containing the deleted element.

3, concat ()

Method: Arrayobject.concat (Arrayx,arrayx,......, Arrayx)
Return value: The method does not alter an existing array, but simply returns a copy of the concatenated array.

4. filter()

方法:arr.filter(callback[, thisArg])

callback: A function used to test each element of an array. Called Using parameters (element, index, array). Returns true to preserve the element (passed test), false is not preserved.

thisArg: Optional. callbackthe value to use when executing this .

The return value, a new array that contains the test pass element. filterdoes not change the original array.

JS Basics-Common Array manipulation methods

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.