iterator
// example1
let ar = ['xiaohesong']
let art = ar[Symbol.iterator]()
art // Array Iterator
art.next() //{value: "xiaohesong", done: false}
art.next() // {value: undefined, done: true}
//example2
let str = 'string'
let strIt = str[Symbol.iterator]()
strIt // StringIterator
// example3
let o = {name: 'xhs'}
let obj = o[Symbol.iterator]() //Uncaught TypeError: o[Symbol.iterator] is not a functionlet range = {
from: 1,
to: 5
};
// We want the for..of to work:
// for(let num of range) ... num=1,2,3,4,5Last updated