zoukankan      html  css  js  c++  java
  • for...in statement

     

    The for...in statement iterates a specified variable over all the enumerable properties of an object. For each distinct property, JavaScript executes the specified statements. Afor...in statement looks as follows:

    for (variable in object) {
      statements
    }
    

      

    Example

    The following function takes as its argument an object and the object's name. It then iterates over all the object's properties and returns a string that lists the property names and their values.

    function dump_props(obj, obj_name) {
      var result = "";
      for (var i in obj) {
        result += obj_name + "." + i + " = " + obj[i] + "<br>";
      }
      result += "<hr>";
      return result;
    }
     
    

      

    For an object car with properties make and modelresult would be:

    car.make = Ford
    car.model = Mustang
    

      

  • 相关阅读:
    1021 个位数统计
    1020 月饼
    1019 数字黑洞
    1018 锤子剪刀布
    1017 A除以B
    1016 部分A+B
    1015 德才论
    1014 福尔摩斯的约会
    cocos2d 间隔动作
    cocos2d 瞬时动作
  • 原文地址:https://www.cnblogs.com/hephec/p/4601267.html
Copyright © 2011-2022 走看看