Update isArrayLike.md
This commit is contained in:
@ -2,17 +2,11 @@
|
|||||||
|
|
||||||
Checks if the provided argument is array-like (i.e. is iterable).
|
Checks if the provided argument is array-like (i.e. is iterable).
|
||||||
|
|
||||||
Use `Array.from()` and a `try... catch` block to check if the provided argument is array-like.
|
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`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const isArrayLike = arr => {
|
const isArrayLike = val =>
|
||||||
try {
|
val != null && typeof val != 'function' && val.length > -1 && val.length % 1 == 0 && val.length <= Number.MAX_SAFE_INTEGER;
|
||||||
Array.from(arr);
|
|
||||||
return true;
|
|
||||||
} catch (e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
Reference in New Issue
Block a user