The slice() Function is used to extract a couple elements from the given Array.
Let us say, we have a Array that contains four names, Mohan, Kriti, Philip and Salim. And we want to extract the elements Kriti and Philip.
<html> <body> <script> var x = ["Mohan", "Kriti", "Philip", "Salim"] var y = x.slice(1,3) document.write(y) </script> </body> </html>
So, we have the below Array,
var x = ["Mohan", "Kriti", "Philip", "Salim"]
And we want to extract the elements Kriti and Philip from the Array.
var y = x.slice(1,3)
<html> <body> <script> var x = ["Mohan", "Kriti", "Philip", "Salim"] var y = x.slice(-3,-1) document.write(y) </script> </body> </html>