Chinaunix

标题: JavaScript for in语句 [打印本页]

作者: feiyang10086    时间: 2011-12-09 16:39
标题: JavaScript for in语句

JavaScript for in语句














Js代码
  1. 1.var tom = {name: 'Tom', gender: 'Male', age: 17};   
  2. 2.for (att in tom) {   
  3. 3.    alert('tom.' + att + ' = ' + tom[att]);   
  4. 4.}   
  5. 5.  
  6. 6.var protocols = ['HTTP', 'FTP', 'SMTP'];   
  7. 7.for (index in protocols) {   
  8. 8.    alert('protocols[' + index + '] = ' + protocols[index]);   
  9. 9.}  
  10. var tom = {name: 'Tom', gender: 'Male', age: 17};
  11. for (att in tom) {
  12.         alert('tom.' + att + ' = ' + tom[att]);
  13. }

  14. var protocols = ['HTTP', 'FTP', 'SMTP'];
  15. for (index in protocols) {
  16.         alert('protocols[' + index + '] = ' + protocols[index]);
  17. }
  18.   
复制代码

作者: 寂寞冲咖啡    时间: 2011-12-24 20:25
谢谢分享  希望于楼主多多交流




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2