Files
30-seconds-of-code/snippets/isArrayLike.md
Angelos Chalaris 5e42f0aaa4 Add some examples
From the old test suite
2020-04-16 23:01:19 +03:00

20 lines
483 B
Markdown

---
title: isArrayLike
tags: 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.
```js
const isArrayLike = obj => obj != null && typeof obj[Symbol.iterator] === 'function';
```
```js
isArrayLike([1, 2, 3]); // true
isArrayLike(document.querySelectorAll('.className')); // true
isArrayLike('abc'); // true
isArrayLike(null); // false
```