To get first N number of elements from an array with JavaScript, we use the slice
method.
For instance, we write
const slicedArray = array.slice(0, n);
to call array.slice
with 0 and n
to return the first n
items in the array
array in a new array.