JavaScript Code

How to remove first item from array using JavaScript?


Remove first item from array

Given an array of items, write a JavaScript program to remove the first item from the array.

Solution

To remove the first item from given array of items using JavaScript, call shift() method on the given array object.

array1.shift() removes the first item from the array array1.

Programs

1. Remove first item from array array1.

let array1 = ['apple', 'banana', 'cherry'];
array1.shift();
console.log(array1);



copyright @2022