JavaScript Common method collation--array

Source: Internet
Author: User

1. Arrayobject.slice (start,end) returns the selected element from an existing array

Parameters Description
Start Necessary. Specify where to start the selection. If it is a negative number, it specifies the position from the end of the array. In other words, 1 refers to the last element, 2 refers to the second-lowest element, and so on.
End Optional. Specifies where to end the selection. The parameter is the array subscript at the end of the array fragment. If this parameter is not specified, then the segmented array contains all elements from start to end of the array. If this parameter is a negative number, it specifies the element starting from the end of the array.
return value

Returns a new array containing elements from start to end (excluding the element) from the Arrayobject.

Description

Note that the method does not modify the array, but instead returns a subarray. If an empty parameter is used, the copy function of the array can be implemented

var ori = [' Bank ', ' hello ', ' Hey ', ' man '];//take [to] left open right closed   Console.log (Ori.slice ());  ["Hello"]//negative number 1,-1 from the start to 1,end for arr.length-1//i.e. [1,arr.length-1]console.log (Ori.slice (1,-1));//["Hello", " Hey "]

Array replication

var ori = [' Bank ', ' hello ', ' Hey ', ' man '];//array copy var res = Ori.slice (); Console.log (ori);//[' Bank ', ' hello ', ' Hey ', ' man '];

  

JavaScript Common method collation--array

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.