日期:2014-05-16  浏览次数:20362 次

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);