To remove first and last element in a JavaScript array, we use shift
to remove the first item and pop
to remove the last item.
For instance, we write
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.shift();
fruits.pop();
to call fruits.shift
to remove the first item from fruits
.
And we call fruits.pop
to remove the last item from fruits
.