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([1, 2, 3]); // true
isArrayLike(document.querySelectorAll('.className')); // true
isArrayLike('abc'); // true
isArrayLike(null); // false