When using the ES6 Symbols iterator, I found that I needed to call the next function each time to print the next item during iteration.
Below is the code snippet:
var title = "Omkar";
var iterateIt = console.log(typeof title[Symbol.iterator]);
var iterable = title[Symbol.iterator]();
do {
console.log(iterable.next().value);
} while (iterable.done)
Currently, it only prints O
.
However, if I repeat
console.log(iterable.next().value);
four more times, I get the desired output. For example, with a longer string like "Chewbacca", I would need to call this console method nine times. Is there a way to streamline this process so that I don't have to manually call next each time? If anyone knows of a better solution, please share.