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
Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️