zoukankan      html  css  js  c++  java
  • ES6参考---for...of方法2

    ES6参考---for...of方法2

    一、总结

    一句话总结:

    for...of方法 可以遍历有 iterator接口的结构,比如对象,比如数组,比如伪数组,比如set、map等
    for...of方法 本质上就是调用对象的iterator接口,用来遍历
    let arr = [1,2,3,4,5];
    for(let num of arr){
      console.log(num);
    }

    二、for...of方法2

    博客对应课程的视频位置:

     1 <!DOCTYPE html>
     2 <html lang="en">
     3 <head>
     4   <meta charset="UTF-8">
     5   <title>06_for_of循环</title>
     6 </head>
     7 <body>
     8 
     9 <!--
    10 for(let value of target){}循环遍历
    11   1. 遍历数组
    12   2. 遍历Set
    13   3. 遍历Map
    14   4. 遍历字符串
    15   5. 遍历伪数组
    16 -->
    17 
    18 <button>按钮1</button>
    19 <button>按钮2</button>
    20 <button>按钮3</button>
    21 
    22 <script type="text/javascript">
    23 
    24     let arr = [1,2,3,4,5];
    25     for(let num of arr){
    26         console.log(num);
    27     }
    28     let set = new Set([1,2,3,4,5]);
    29     for(let num of set){
    30         console.log(num);
    31     }
    32     let str = 'abcdefg';
    33     for(let num of str){
    34         console.log(num);
    35     }
    36     let btns = document.getElementsByTagName('button');
    37     for(let btn of btns){
    38         console.log(btn.innerHTML);
    39     }
    40 
    41 </script>
    42 </body>
    43 
    44 </html>
     
  • 相关阅读:
    模态对话框可能导致程序崩溃
    C++实现将字符串循环左移n个位置
    Android Gallery图片显示和文字提示及Menu 菜单
    android代码实现ScaleAnimation
    Android系统内存管理的问题
    android打电话发短信
    android开发之屏幕设置
    输入法
    黄金周
    气筒
  • 原文地址:https://www.cnblogs.com/Renyi-Fan/p/12590416.html
Copyright © 2011-2022 走看看