mirror of
https://github.com/bendtherules/blog-hashnode-backup.git
synced 2026-08-18 13:42:04 +00:00
update post: How does in-built Array iterator work?
This commit is contained in:
@@ -17,8 +17,6 @@ When we use spread operator, like `[...someArray]` - it treats someArray as a ge
|
|||||||
|
|
||||||
This is how the iterable/iterator stuff works.
|
This is how the iterable/iterator stuff works.
|
||||||
|
|
||||||
In our case, Iterable is `someArray` - which has a special property `Symbol.iterator` whose value is a method. Calling this method returns a iterable (`iter`), which has `.next()` method. Calling this method returns all the values one-by-one.
|
|
||||||
|
|
||||||
## Array Iterator
|
## Array Iterator
|
||||||
|
|
||||||
Array has in-built support for iterable/iterator protocol, through prototype. Array.prototype has a method with key `Symbol.iterator`, which creates a ArrayIterator.
|
Array has in-built support for iterable/iterator protocol, through prototype. Array.prototype has a method with key `Symbol.iterator`, which creates a ArrayIterator.
|
||||||
|
|||||||
Reference in New Issue
Block a user