首页 > 其他 > 详细

for...in statement

时间:2015-06-26 00:25:20      阅读:135      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!