-3
I would like to know how to remove the first element of an array.
//Array atual:
[1, 2, 3, 4, 5]
//Como quero que fique:
[2, 3, 4, 5]
-3
I would like to know how to remove the first element of an array.
//Array atual:
[1, 2, 3, 4, 5]
//Como quero que fique:
[2, 3, 4, 5]
2
The method shift()
removes the first element of an array and returns that element. This method changes the size of the array.
example:
const compras = ['café', 'banana', 'queijo']
compras.shift()
console.log(compras) //["banana", "queijo"]
For more information see
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift
Browser other questions tagged javascript array
You are not signed in. Login or sign up in order to post.
Try to use
array.shift()
. This will remove the first element.– user225490