Update last.md

This commit is contained in:
Angelos Chalaris
2019-12-11 09:52:33 +02:00
committed by GitHub
parent 980499db57
commit f8325eabd8

View File

@ -5,9 +5,7 @@ tags: array,beginner
Returns the last element in an array.
Check if `arr` is truthy and has a `length` property, use `arr.length - 1` to
compute the index of the last element of the given array and returning it,
otherwise return `undefined`
Check if `arr` is truthy and has a `length` property, use `arr.length - 1` to compute the index of the last element of the given array and return it, otherwise return `undefined`.
```js
const last = arr => (arr && arr.length ? arr[arr.length - 1] : undefined);