Blogger Information
Blog 38
fans 0
comment 0
visits 18959
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
字符串和数组的api演示
Blackeye
Original
341 people have browsed it

hw

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>字符串和数组的api</title>
  8. </head>
  9. <body>
  10. <script>
  11. // 自选不少于5个字符串和数组的api实例演示,特别是数组遍历方法
  12. // 字符串
  13. let str = "php中文网";
  14. // 1.字符串长度
  15. out(str.length);
  16. // 2.索引获取元素
  17. out(str.charAt(0));
  18. // 3.元素获取索引
  19. out(str.indexOf("文"));
  20. out(str.search("文"));
  21. // 4.字符串拼装
  22. out(str.concat(' php.cn'));
  23. // 5.字符串替换
  24. out(str.replace("中文网",".cn"));
  25. // 6.字符串查询
  26. out(str.slice(0,3));
  27. // 7.substr
  28. out(str.substr(-3,3));
  29. // 8.split分割字符串为数组
  30. out(str.replace("中文网",".cn").split('.'));
  31. ///////////////////////////////////////////////////////////////////////
  32. // 数组
  33. let arr = [1,2,3,4,5,6,7,8,9];
  34. // 1.foreach,Map
  35. arr.forEach((item,index)=>{out(`${index}:${item}`)});
  36. out(arr.map((item,index)=>`index:${index},item:${item}`));
  37. // 2.every,some
  38. out(arr.every(item=>item>=3));
  39. out(arr.every(item=>item>=1));
  40. out(arr.some(item=>item>=3));
  41. out(arr.some(item=>item>=1));
  42. // 3.filter,find,findIndex
  43. out(arr.filter(item=>item>=3));
  44. out(arr.find(item=>item>=3));
  45. out(arr.findIndex(value=>value>=8));
  46. out(arr.findIndex(value=>value>=10));
  47. // 4.reduce
  48. out(arr.reduce((res,index)=>res+index,0));
  49. out(arr.reduce((res,index)=>res+index,100));
  50. // ConsoleOutHelper
  51. function out(outprint){
  52. return console.log(outprint);
  53. }
  54. </script>
  55. </body>
  56. </html>
Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
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