421 B
421 B
isArrayLike
Checks if the provided argument is array-like (i.e. is iterable).
Use Array.from() and a try... catch block to check if the provided argument is array-like.
const arr = (arr) => {
try{
Array.from(arr);
return true;
}
catch(e){
return false;
}
}
isArrayLike(document.querySelector('.className')) // true
isArrayLike('abc') // true
isArrayLike(null) // false