First n elements
Gets the first
n elements of an array.
Array.prototype.slice()with a start value of
0and an end value of
nto get the first
const firstN = (arr, n) => arr.slice(0, n);
firstN(['a', 'b', 'c', 'd'], 2); // ['a', 'b']
Written by Angelos Chalaris
If you want to keep in touch, follow me on GitHub or Twitter.