Files
30-seconds-of-code/snippets/isArrayLike.md
Isabelle Viktoria Maciohsek 8bf67754ce Make expertise a field
2022-03-01 20:21:45 +02:00

582 B

title, tags, expertise, firstSeen, lastUpdated
title tags expertise firstSeen lastUpdated
Value is array-like type,array intermediate 2017-12-31T14:53:01+02:00 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