码迷,mamicode.com
首页 > 其他好文 > 详细

for...in statement

时间:2015-06-26 00:26:00      阅读:108      评论:0      收藏:0      [点我收藏+]

标签:

 

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

  

for...in statement

标签:

原文地址:http://www.cnblogs.com/hephec/p/4601267.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!