EN
JavaScript - remove first and last element in array
0 points
In this article, we would like to show you how to remove the first and last element in an array in JavaScript.
Quick solution:
xxxxxxxxxx
1
const array = ['a', 'b', 'c', 'd'];
2
3
array.shift(); // removes first element
4
array.pop(); // removes last element
5
6
console.log(array); // [ 'b', 'c' ]
xxxxxxxxxx
1
let array = ['a', 'b', 'c', 'd'];
2
3
array = array.slice(1, -1);
4
5
console.log(array); // [ 'b', 'c' ]