Merge pull request #716 from Bruce-Feldman/Simplify-Is_Array_Like

[ENHANCEMENT] Simplified isArrayLike
This commit is contained in:
Angelos Chalaris
2018-08-14 20:38:53 +03:00
committed by GitHub
2 changed files with 3 additions and 15 deletions

View File

@ -2,16 +2,10 @@
Checks if the provided argument is array-like (i.e. is iterable).
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.
Check if the provided argument is not `null` and that its `Symbol.iterator` property is a function.
```js
const isArrayLike = val => {
try {
return [...val], true;
} catch (e) {
return false;
}
};
const isArrayLike = obj => obj != null && typeof obj[Symbol.iterator] === 'function';
```
```js

View File

@ -1,8 +1,2 @@
const isArrayLike = val => {
try {
return [...val], true;
} catch (e) {
return false;
}
};
const isArrayLike = obj => obj != null && typeof obj[Symbol.iterator] === 'function';
module.exports = isArrayLike;