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