Files
30-seconds-of-code/snippets/isArrayLike.md
Isabelle Viktoria Maciohsek caa67e2a49 Update snippet descriptions
2020-10-20 23:02:01 +03:00

487 B

title, tags
title tags
isArrayLike type,array,intermediate

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