Categories
JavaScript Answers

How to remove the first element from array and return the array minus the first element with JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *