Blogger Information
Blog 42
fans 5
comment 0
visits 38605
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
js中 for in, for of
张浩刚
Original
1377 people have browsed it

for in 和 for of , 新功能:字符集 ``

  1. ``字符集,`这是新功能:${变量名} 不用“+”的连接符`
  2. ******************************
  3. let a = [
  4. {name:'张明轩', age:3},
  5. {name:'张明朗', age:1}
  6. ];
  7. //for( in ) 这里的i为数组a的键
  8. for(let i in a){
  9. document.write(
  10. ` //这个为js新功能,字符集,可以省略连接符+ , 变量使用: ${变量名}
  11. <ul>
  12. //这里调用的是数组下的对象类,i为键
  13. <li>姓名:${a[i].name} 年龄:${a[i].age}</li>
  14. </ul>
  15. `
  16. );
  17. }
  18. **********************************
  19. let b = ['张浩刚', 32];
  20. //for( of ) 下面的n直接就是b的值
  21. for(let n of b){
  22. document.write(
  23. `
  24. ${n}
  25. `
  26. );
  27. }
  28. ***********************************
  29. //这里使用for of 更方便
  30. let a = [
  31. {name:'张明轩', age:3},
  32. {name:'张明朗', age:1}
  33. ];
  34. for(let i of a){
  35. document.write(
  36. ` //这个为js新功能,字符集,可以省略连接符+ , 变量使用: ${变量名}
  37. <ul>
  38. //这里调用的是数组下的对象类
  39. <li>姓名:${n.name} 年龄:${n.age}</li>
  40. </ul>
  41. `
  42. );
  43. }
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post