-
-
Notifications
You must be signed in to change notification settings - Fork 0
iterable
Nicholas Berlette edited this page Jun 19, 2025
·
1 revision
function isIterable<T>(it: unknown): it is Iterable<T>;
Checks if a given value is an iterable. This includes arrays, strings, maps,
sets, and any other value with a Symbol.iterator
method. If you need to check
for iterable objects specifically, use isIterableObject
.
Name | Info |
---|---|
it |
The value to check. |
true
if the value is an iterable, false
otherwise.
Iterables
import { isIterable } from "jsr:@nick/is/iterable";
console.log(isIterable([1, 2])); // true
console.log(isIterable("foo")); // true
console.log(isIterable(new Map())); // true
console.log(isIterable(new Set())); // true
console.log(isIterable({ [Symbol.iterator]: () => {} })); // true
console.log(isIterable({})); // false