当前位置: 代码迷 >> JavaScript >> JavaScript for in话语
  详细解决方案

JavaScript for in话语

热度:373   发布时间:2012-11-09 10:18:48.0
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);
  相关解决方案