Javatpoint Logo
Javatpoint Logo

JavaScript Array slice() method

The JavaScript array slice() method extracts the part of the given array and returns it. This method doesn't change the original array.

Syntax

The slice() method is represented by the following syntax:

Parameter

start - It is optional. It represents the index from where the method starts to extract the elements.

end - It is optional. It represents the index at where the method stops extracting elements.

Return

A new array contains the extracted elements.

JavaScript Array slice() method example

Here, we will understand slice() method through various examples.

Example 1

Let's see a simple example to extract an element from the given array.

Test it Now

Output:

Node.js

Example 2

Let's see one more example to extract various element from the given array.

Test it Now

Output:

AngularJS,Node.js,JQuery

Example 3

In this example, we will provide the negative values as index to extract elements.

Test it Now

Output:

AngularJS,Node.js,JQuery

Next TopicJavaScript Array




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA