I like your real demo, but I think this article failed to mention an important point.
Iterators are supposed to be used in conjunction with iterables.
In your example
// Create an arrayletnames=['wale','ali','john','bubu'];// pass the array into the Iterator functionletname=Iterator(names);
I understand that you want to show how iterators work, but iterators are not functions.
You can even use the name array directly since it is an iterable.
I like your real demo, but I think this article failed to mention an important point.
In your example
I understand that you want to show how iterators work, but iterators are not functions.
You can even use the
name
array directly since it is an iterable.I wrote an in depth article on this very topic, please check it out.