To remove the first element from a JavaScript array, you can use the shift()
method. This method removes the first element of the array and returns it. Here’s an example:
let arr = [1, 2, 3, 4];
let firstElement = arr.shift();
console.log(firstElement); // outputs 1
console.log(arr); // outputs [2, 3, 4]
In this example, shift()
is called on the arr
array, and the first element (1
) is removed and stored in the firstElement
variable. The resulting array is [2, 3, 4]
.
+ There are no comments
Add yours