remove first object from array javascript code example

Example 1: remove first element of array javascript

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

Example 2: remove first element of array javascript

var fruits = ["Banana", "Orange", "Apple", "Mango"]
fruits.shift()

Example 3: es6 remove first element of array

var myarray = ["item 1", "item 2", "item 3", "item 4"];

//removes the first element of the array, and returns that element.
alert(myarray.shift());
//alerts "item 1"

//removes the last element of the array, and returns that element.
alert(myarray.pop());
//alerts "item 4"

Example 4: how to remove first element of array in javascript

let numbers = ["I'm Not A Number!", 1, 2, 3];
numbers.shift();