jskatas.org Continuously Learn JavaScript. Your Way.

Iterator: usage

Donate to NGO Julenka. Support Ukranians in need. Julenka is an NGO which my brother founded in 2011 to support Ukranian families and kids in need.

create an iterator/iterable

  • the usersIterable should be iterable
  • the iterator of usersIterable should return an object
  • the iterator of usersIterable should have a next function

fill the iterable with content using ConsumableUsers

using the iterator

  • should return Alice as first user
  • should return Bob as second user
  • should return done:true, which means there are no more items

using built-in constructs

  • use Array.from() to convert an iterable to an array
  • use for-of to loop over an iterable
  • use the spread-operator to convert/add iterable to an array
  • destructure an iterable like an array