The slice() method is represented by the following syntax:
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.
A new array contains the extracted elements.
Here, we will understand slice() method through various examples.
Let's see a simple example to extract an element from the given array.Test it Now
Let's see one more example to extract various element from the given array.Test it Now
In this example, we will provide the negative values as index to extract elements.Test it Now