EN
JavaScript - remove first element from array
0 points
In this article, we would like to show you how to remove the first element from an array in JavaScript.
Quick solution:
xxxxxxxxxx
1
var array = ['a', 'b', 'c'];
2
3
array.shift();
4
5
console.log(array); // [ 'b', 'c' ]
In this example, we use slice()
method to remove the first element from array
.
xxxxxxxxxx
1
var array = ['a', 'b', 'c'];
2
3
var newArray = array.slice(1);
4
5
console.log(newArray); // [ 'b', 'c' ]