zoukankan      html  css  js  c++  java
  • JavaScript: For , For/in , For/of

     For:

    define:

    The for statement can customize how many times you want to execute code

    Grammar:

      for (condition 1; condition 2; condition 3)
      {
            code
      }
     

    Condition explain:

    condition describe
    1 prestart before beginning.
    2 loop condition.
    3 Execute after the loop has been executed.

    Example:

    for (var i=0; i<5; i++)
    {
          x=x + "The number is " + i + "<br>";
    }

    The code 's output:

        The number is 0
        The number is 1
        The number is 2
        The number is 3
        The number is 4


    For/in:

    define:

    The for/in statement is used to loop through the object properties。

    Grammar:

      for (var in object) {
         code
      }

    parameter values:

    parameterdescribe
    var

    Must.variable can be an array element or an attribute of an object.

    (指定的变量可以是数组元素,也可以是对象的属性。)

    object

    Must.Object that specifies the iteration.

    (指定迭代的的对象。)

    Example:

    1 var string = {lesson:"web", verb:"is", describe:"fun"}; 
    2 
    3 var text = "";
    4 var x;
    5 for (x in string) {
    6 
    7     text += string[x]+" ";
    8 }

    The code 's output:

        web is fun 


    For/of:

    define:

    The for/of statements creates a loop iterating over iterable objects.

    Grammar:

      for (variable of iterable) {
          statement
      }

    parameter values:

    parameterdescribe
    variable

    On each iteration a value of a different property is assigned to variable.

    (在每次迭代中,将不同属性的值分配给变量。)

    object

    Object whose iterable properties are iterated.

    (被迭代枚举其属性的对象。)

    Example:

    1 let iterable = [10, 20, 30];
    2 
    3 for (let value of iterable) {
    4     value += 1;
    5     console.log(value);
    6 }

    The code 's output:

        11 21 31


     Related Pages:

    JavaScript for    :          http://www.runoob.com/js/js-loop-for.html

    JavaScript for/in :         http://www.runoob.com/jsref/jsref-forin.html 

    MDN - for...of :              https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Statements/for...of

    Javascript statement :   http://www.runoob.com/jsref/jsref-statements.html

  • 相关阅读:
    TFS实现需求工作项自动级联保存
    Oracle PL/SQL Developer集成TFS进行团队脚本文件版本管理
    TFS2017持续集成构建
    TFS 测试用例步骤数据统计
    精细化容量管理的设备成本优化之路
    腾讯Web工程师的前端书单
    React Native For Android 架构初探
    SQL系列(八)—— 分组(group by)
    SQL系列(七)—— 相似(like)
    SQL系列(六)—— 过滤(where)
  • 原文地址:https://www.cnblogs.com/chenzhihong294/p/9943264.html
Copyright © 2011-2022 走看看