From f8d3c5ccf55b32d633fe8059f5809e9b636241c8 Mon Sep 17 00:00:00 2001 From: 30secondsofcode <30secondsofcode@gmail.com> Date: Tue, 14 Aug 2018 17:40:14 +0000 Subject: [PATCH] Travis build: 226 --- README.md | 10 ++-------- docs/type.html | 8 +------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 2218d95ee..4a1d737ab 100644 --- a/README.md +++ b/README.md @@ -8286,16 +8286,10 @@ is(Boolean, new Boolean(true)); // true 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'; ```
diff --git a/docs/type.html b/docs/type.html index a32019b4f..958ae2533 100644 --- a/docs/type.html +++ b/docs/type.html @@ -96,13 +96,7 @@ is(Number, new Number(1)); // true is(Boolean, true); // true is(Boolean, new Boolean(true)); // true -

isArrayLike

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.

const isArrayLike = val => {
-  try {
-    return [...val], true;
-  } catch (e) {
-    return false;
-  }
-};
+

isArrayLike

Checks if the provided argument is array-like (i.e. is iterable).

Check if the provided argument is not null and that its Symbol.iterator property is a function.

const isArrayLike = obj => obj != null && typeof obj[Symbol.iterator] === 'function';
 
isArrayLike(document.querySelectorAll('.className')); // true
 isArrayLike('abc'); // true
 isArrayLike(null); // false