444 B
444 B
title, type, language, tags, author, cover, dateModified
| title | type | language | tags | author | cover | dateModified | |
|---|---|---|---|---|---|---|---|
| First n elements | snippet | javascript |
|
chalarangelo | digital-nomad-16 | 2022-07-22T05:00:00-04:00 |
Gets the first n elements of an array.
- Use
Array.prototype.slice()with a start value of0and an end value ofnto get the firstnelements ofarr.
const firstN = (arr, n) => arr.slice(0, n);
firstN(['a', 'b', 'c', 'd'], 2); // ['a', 'b']