Sometimes, we want to remove the first element from array and return the array minus the first element with JavaScript.
In this article, we’ll look at how to remove the first element from array and return the array minus the first element with JavaScript.
How to remove the first element from array and return the array minus the first element with JavaScript?
To remove the first element from array and return the array minus the first element with JavaScript, we can use the array slice
method.
For instance, we write
const myArray = ["item 1", "item 2", "item 3", "item 4"];
const sliced = myArray.slice(1);
to call myArray.slice
with 1 to return an array with all the myArray
items except the first one.
Conclusion
To remove first element from array and return the array minus the first element with JavaScript, we can use the array slice
method.