Update isArrayLike.md
This commit is contained in:
@ -2,15 +2,13 @@
|
|||||||
|
|
||||||
Checks if the provided argument is array-like (i.e. is iterable).
|
Checks if the provided argument is array-like (i.e. is iterable).
|
||||||
|
|
||||||
Check that the object is not a function or `null` and that its `length` property is a non-negative integer below `Number.MAX_SAFE_INTEGER`.
|
Use the spread operator (`...`) to check if the provided argument is iterable inside a `try... catch` block and the comma operator (`,`) to return the appropriate value.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const isArrayLike = val =>
|
const isArrayLike = val =>
|
||||||
val != null &&
|
try {return [...val], true; }
|
||||||
typeof val != 'function' &&
|
catch (e) { return false; }
|
||||||
val.length > -1 &&
|
};
|
||||||
val.length % 1 == 0 &&
|
|
||||||
val.length <= Number.MAX_SAFE_INTEGER;
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
Reference in New Issue
Block a user