Array in JavaScript – slice() Method

Array in JavaScript has slice() method that is used to extract a section of an array. This method returns a new array.

Syntax is as below:

begin: Zero-based index at which to begin the extraction. As a negative index, start indicates an offset from the end of the sequence.
end: Optional, zero-based index at which to end the extraction.

Return Value:

slice() method returns the extracted array based on the passed parameters.

Example:

Output: This will give the following output:

To understand the slice() method in better way Try yourself.

You Might Interested In

Leave a Reply

Enclose a code block like: <pre><code>Your Code Snippet</code></pre>.