JavaScript Slice() method

 

JavaScript Array slice()

array.slice(start, end)

Description

The slice() method returns selected elements in an array, as a new array.

The slice() method selects from a given start, up to a (not inclusive) given end.

The slice() method does not change the original array.


 const fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
                //  -5         -4      -3         -2          -1

    console.log(fruits.slice(-4, -1));



Comments

Popular posts from this blog

Javascript Array Concat and Join Method

JavaScript While Loop

JavaScript pop() Method