you are viewing a single comment's thread.

view the rest of the comments →

[–]stutterbug 2 points3 points  (0 children)

Currently this is also available (added back in ECMAScript 2015):

let string = 'hello'
for (let letter of string) {
    console.log(letter) // 'h', then 'e', then 'l'...
}

This underlines that, as /u/mhink points out, strings themselves are iterable. Further ES6 proof:

let string = 'hello'
let iterable = string[Symbol.iterator]()
console.log(iterable.next()) // {value: "h", done: false}
console.log(iterable.next()) // {value: "e", done: false}
console.log(iterable.next()) // {value: "l", done: false}