remove the first item from an array 1

remove the first item from an array

var arr = [1, 2, 3, 4]; 
var theRemovedElement = arr.shift(); // theRemovedElement == 1
console.log(arr); // [2, 3, 4]

Here is what the above code is Doing:
1. We create an array called arr.
2. We call the shift() method on arr.
3. The shift() method removes the first element from arr and returns it.
4. We store the returned element in a variable called theRemovedElement.
5. We log the value of theRemovedElement to the console.
6. We log the value of arr to the console.

Similar Posts