The .shift() method removes the first element of an array. Then you can return the remaining:
const array = ["item 1", "item 2", "item 3", "item 4"];
array.shift();
console.log(array);
As others have suggested, you could also use slice(1):
const array = ["item 1", "item 2", "item 3", "item 4"];
console.log(array.slice(1));
Answer from Jesper Højer on Stack OverflowThe .shift() method removes the first element of an array. Then you can return the remaining:
const array = ["item 1", "item 2", "item 3", "item 4"];
array.shift();
console.log(array);
As others have suggested, you could also use slice(1):
const array = ["item 1", "item 2", "item 3", "item 4"];
console.log(array.slice(1));
Why not use ES6?
const array = ["item 1", "item 2", "item 3", "item 4"];
const [, ...rest] = array;
console.log(rest)
Videos
The easiest way is using shift(). If you have an array, the shift function shifts everything to the left.
var arr = [1, 2, 3, 4];
var theRemovedElement = arr.shift(); // theRemovedElement == 1
console.log(arr); // [2, 3, 4]
Just use arr.slice(startingIndex, endingIndex).
If you do not specify the endingIndex, it returns all the items starting from the index provided.
In your case arr=arr.slice(1).
The .shift() method removes the first element of an array. Then you can return the remaining:
const array = ["item 1", "item 2", "item 3", "item 4"];
array.shift();
console.log(array);
As others have suggested, you could also use slice(1):
const array = ["item 1", "item 2", "item 3", "item 4"];
console.log(array.slice(1));
Why not use ES6?
const array = ["item 1", "item 2", "item 3", "item 4"];
const [, ...rest] = array;
console.log(rest)
shift() is ideal for your situation. shift() removes the first element from an array and returns that element. This method changes the length of the array.
array = [1, 2, 3, 4, 5];
array.shift(); // 1
array // [2, 3, 4, 5]
For a more flexible solution, use the splice() function. It allows you to remove any item in an Array based on Index Value:
var indexToRemove = 0;
var numberToRemove = 1;
arr.splice(indexToRemove, numberToRemove);