Files
30-seconds-of-code/snippets/isArrayLike.md
Angelos Chalaris 611729214a Snippet format update
To match the starter (for the migration)
2019-08-13 10:29:12 +03:00

18 lines
450 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(document.querySelectorAll('.className')); // true
isArrayLike('abc'); // true
isArrayLike(null); // false
```