Skip to content

Iteratable

James edited this page May 29, 2017 · 1 revision

Set

const ChainedSet = require('../ChainedSet')
const set = new ChainedSet().add('eh')
for-of
for (const arr of set) {
  const [key, val] = arr
  arr.length === 2
  key === 0
  val === 'eh'
}
values
for (const val in set.values()) {
  console.log(val)
}

Map

const ChainedMap = require('../ChainedMap')
const map = new ChainedMap().set('eh', 'eh!').set('eh2', 'eh2!')
for-of
for (const arr of map) {
  const [key, val] = arr
  arr.length === 2
  key.includes('eh') === true
  val.includes('eh') === true
}
entries
const obj = map.entries()
for (const prop in obj) {
  const val = obj[prop]
  console.log({[prop]: val})
}
Clone this wiki locally