This post will discuss how to remove the first element from an array in JavaScript.

1. Using Array.prototype.shift() function

The standard method to remove the first element from an array is using shift() method. The following example demonstrates the usage of the shift() to in-place remove the first element from the array.

Download  Run Code

2. Using Array.prototype.splice() function

The splice() method is frequently used to remove existing elements from the array.

The following code creates an array containing five elements, then calls the slice() method to create a shallow copy of all the original array values except the first.

Download  Run Code

 
You can easily extend the above code to return everything but the first n elements from the array.

Download  Run Code

3. Using Lodash Library

If you’re using the Lodash JavaScript library in your project, you can use the tail() method, which will return everything but the first element of the array. Note that this doesn’t modify the original array but returns a new array.

Download Code

4. Using Underscore Library

Alternatively, using the Underscore JavaScript library, you can use the rest() method to get a copy of the array with the first element removed.

Download Code

 
To remove the first n elements from the array, you can pass the total number of elements to the function.

Download Code

That’s all about removing the first element from an array in JavaScript.