Answered
When coding in JavaScript, I have an array that I need to get each element from, but exclude the first one at the 0
index position.
For example, this array:
[1, 4, 21, 41]
Should be converted into this new array:
[4, 21, 41]
Thanks in advance!
You can use the array.slice(startIndex, endIndex)
method:
array.slice(1)
If you leave the endIndex
parameter empty, it returns all the elements starting at the index you provided.
shift() is the easiest way to do this:
var array = [1, 4, 21, 41]
array.shift()
// array = [4, 21, 41]
var array = [1, 4, 21, 41]
const [, ...newArray] = array
console.log(newArray) // [4, 21, 41]