Files
30-seconds-of-code/snippets/last.md
Angelos Chalaris 611729214a Snippet format update
To match the starter (for the migration)
2019-08-13 10:29:12 +03:00

16 lines
264 B
Markdown

---
title: last
tags: array,beginner
---
Returns the last element in an array.
Use `arr.length - 1` to compute the index of the last element of the given array and returning it.
```js
const last = arr => arr[arr.length - 1];
```
```js
last([1, 2, 3]); // 3
```