Select Element in Array() to a new Array() JavaScript

tsitohaina

Tsito Ranjafy

Posted on June 19, 2024

Select Element in Array() to a new Array() JavaScript

JavaScript Array slice()
Select elements:

const fruits = ["Banana","Orange","Lemon","Apple","Mango"];
const citrus = fruits.slice(1, 3);
console.log(citrus);
Enter fullscreen mode Exit fullscreen mode

Select elements using negative values:

const fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
const myBest = fruits.slice(-3, -1);
console.log(myBest);
Enter fullscreen mode Exit fullscreen mode

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.

💖 💪 🙅 🚩
tsitohaina
Tsito Ranjafy

Posted on June 19, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related