Skip to content

Check whether a javascript object is iterable via Symbol.iterator

License

Notifications You must be signed in to change notification settings

biancojs/is-iterable

Repository files navigation

bianco.is-iterable

This package is no longer maintained

Build Status

NPM version NPM downloads MIT License

Usage

import isIterable from 'bianco.is-iterable'

// An array should be iterable
const arr = [1, 2, 3]
isIterable(arr) // => true of course

// A generator should be iterable
const gen = (function *() {
  yield Math.random()
})()
isIterable(gen) // => true

// A DOM nodes list should be iterable
const lis = document.querySelectorAll('li')
isIterable(lis)  // => depends on the browser

// An object should not be iterable
const obj = { foo: 'foo', bar: 'bar' }
isIterable(obj) // => false

API

  • isIterable returns true if the object could be looped in a "for of" otherwise false

About

Check whether a javascript object is iterable via Symbol.iterator

Resources

License

Stars

Watchers

Forks

Packages

No packages published