For...Of

  • 遍历数组
        const array1 = ['a', 'b', 'c'];
        for (const element of array1) {
            console.log(element);
            // a
            // b
            // c
}
  • 遍历字符串
      const str = 'abc';
        for (const element of str) {
            console.log(element);
            // a
            // b
            // c
        }

  

posted @ 2020-03-23 19:30  banzhuxiang  阅读(110)  评论(0)    收藏  举报