Iterables thumbnail
Iterables
javascript.info
Iterable objects are a generalization of arrays. To make the range object iterable (and thus let for..of work) we need to add a method to the object named Symbol.iterator (a special built-in symbol just for that). There’s a universal method Array.from that takes an iterable or array-like value and m
4 Users
0 Comments
27 Highlights
0 Notes

Top Highlights

  • Iterable objects are a generalization of arrays.
  • To make the range object iterable (and thus let for..of work) we need to add a method to the object named Symbol.iterator (a special built-in symbol just for that).
  • There’s a universal method Array.from that takes an iterable or array-like value and makes a “real” Array from it.
  • When for..of starts, it calls that method once (or errors if not found). The method must return an iterator – an object with the method next. Onward, for..of works only with that returned object. When for..of wants the next value, it calls next() on that object. The result of next() must have the form {done: Boolean, value: any}, where done=true me...
  • // 3. next() is called on each iteration by the for..of loop

Ready to highlight and find good content?

Glasp is a social web highlighter that people can highlight and organize quotes and thoughts from the web, and access other like-minded people’s learning.