How to use shift() Method In Javascript

The JavaScript Array shift() Method removes the first element of the array thus reducing the size of the original array by 1.

Example: In this example, we are using shift() Method.

Javascript
function func() {

    // Original array
    let array = [34, 234, 567, 4];

    // Checking for condition in array
    let value = array.shift();
    console.log(array);
}
func();

Output
[ 234, 567, 4 ]

How to get all Elements Except First in JavaScript Array?

We will find all the elements in a given array except for the first one using JavaScript. We have a few methods to do this in JavaScript that are described below:

Table of Content

  • Using for loop
  • Using slice() Method
  • Using Array.filter method
  • JavaScript Array.reduce() Method
  • Using shift() Method
  • Using Array.from() Method

Similar Reads

Using for loop

In this method, we will use a for loop to grab all the elements except the first. We know that in an array the first element is present at index ‘0’. We will run a loop from 1 to array.length and save those remaining elements to another array....

Using slice() Method

The slice() is a method that returns a slice of an array. It takes two arguments, the start and end index....

Using Array.filter method

The Array.filter() method is used to create a new array with elements from the existing array which satisfies the condition....

JavaScript Array.reduce() Method

The Array.reduce() is used to perform the function on each element of an array and form a single element....

Using shift() Method

The JavaScript Array shift() Method removes the first element of the array thus reducing the size of the original array by 1....

Using Array.from() Method

The Array.from() method creates a new array instance from an array-like or iterable object. We can use it to create a new array starting from the second element of the original array, effectively excluding the first element....

Contact Us