Files
30-seconds-of-code/snippets/js/s/is-array-like.md
2023-05-07 16:07:29 +03:00

583 B

title, type, language, tags, cover, dateModified
title type language tags cover dateModified
Value is array-like snippet javascript
type
array
colorful-plastic 2020-10-20T23:02:01+03:00

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