`
hlzhao
  • 浏览: 24627 次
  • 性别: Icon_minigender_1
  • 来自: 常州
最近访客 更多访客>>
社区版块
存档分类
最新评论

JavaScript for in语句

阅读更多

 

var tom = {name: 'Tom', gender: 'Male', age: 17};
for (att in tom) {
	alert('tom.' + att + ' = ' + tom[att]);
}

var protocols = ['HTTP', 'FTP', 'SMTP'];
for (index in protocols) {
	alert('protocols[' + index + '] = ' + protocols[index]);
}

var comment = 'It is beautiful.';
var str = '';
for (s in comment) {
	str = str + ', ' + s;
}
str = str.slice(2);
alert(str);
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics