Prepare repository for merge

This commit is contained in:
Angelos Chalaris
2023-05-01 22:35:56 +03:00
parent fc4e61e6fa
commit b3ad01863a
578 changed files with 0 additions and 0 deletions

View File

@ -0,0 +1,20 @@
---
title: Last n elements
type: snippet
tags: [array]
author: chalarangelo
cover: interior-5
dateModified: 2022-07-23T05:00:00-04:00
---
Gets the last `n` elements of an array.
- Use `Array.prototype.slice()` with a start value of `-n` to get the last `n` elements of `arr`.
```js
const lastN = (arr, n) => arr.slice(-n);
```
```js
lastN(['a', 'b', 'c', 'd'], 2); // ['c', 'd']
```