368 B
368 B
title, tags, author, cover, firstSeen
| title | tags | author | cover | firstSeen |
|---|---|---|---|---|
| Last n elements | array | chalarangelo | interior-5 | 2022-07-23T05:00:00-04:00 |
Gets the last n elements of an array.
- Use
Array.prototype.slice()with a start value of-nto get the lastnelements ofarr.
const lastN = (arr, n) => arr.slice(-n);
lastN(['a', 'b', 'c', 'd'], 2); // ['c', 'd']