Array-like object
Value is array-like
Checks if the provided argument is array-like (i.e. is iterable).
- Check if the provided argument is not
null
and that itsSymbol.iterator
property is a function.
const isArrayLike = obj =>
obj != null && typeof obj[Symbol.iterator] === 'function';
isArrayLike([1, 2, 3]); // true
isArrayLike(document.querySelectorAll('.className')); // true
isArrayLike('abc'); // true
isArrayLike(null); // false
Example
Last updated on February 16, 2023