美文网首页
es6--迭代器

es6--迭代器

作者: lvyweb | 来源:发表于2021-06-14 14:39 被阅读0次

    Inerator
    两个核心 是一种新的遍历机制

    1. 迭代器是一个接口,能快捷的访问数据,通过Symbol.iterator创建迭代器,通过迭代器的next方法获取迭代之后的结果
    2. 迭代器是用于遍历数据结构的指针(数据库的游标)

    使用迭代:

      const items = ['one','two','three'];
        const ite = items[Symbol.iterator]();
        console.log(ite);//Array Iterator {}
        console.log(ite.next())//{value: "one", done: false}
        console.log(ite.next())//{value: "two", done: false}
        console.log(ite.next())//{value: "three", done: false}//done为false表示遍历继续,为true表示遍历完成
        console.log(ite.next())//{value: undefined, done: true}
    

    相关文章

      网友评论

          本文标题:es6--迭代器

          本文链接:https://www.haomeiwen.com/subject/pvqoeltx.html