Select Element in Array() to a new Array() JavaScript
Tsito Ranjafy
Posted on June 19, 2024
JavaScript Array slice()
Select elements:
const fruits = ["Banana","Orange","Lemon","Apple","Mango"];
const citrus = fruits.slice(1, 3);
console.log(citrus);
Select elements using negative values:
const fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
const myBest = fruits.slice(-3, -1);
console.log(myBest);
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.
💖 💪 🙅 🚩
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
webdev A Tale of WeakMap and WeakSet in JavaScript: The Guardians of Forgotten Secrets
November 29, 2024