Merge pull request #1166 from dym-sh/patch-1
use isArray instead of instanceof
This commit is contained in:
@ -8,7 +8,7 @@ Returns the last element in an array.
|
|||||||
Check if `arr` is an instance of an `Array`, use `arr.length - 1` to compute the index of the last element of the given array and return it, otherwise return `undefined`.
|
Check if `arr` is an instance of an `Array`, use `arr.length - 1` to compute the index of the last element of the given array and return it, otherwise return `undefined`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const last = arr => (arr instanceof Array ? arr[arr.length - 1] : undefined);
|
const last = arr => (Array.isArray(arr) ? arr[arr.length - 1] : undefined);
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
Reference in New Issue
Block a user