11_ES6新增循环.html 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <script>
  10. let arr = [1,2,3,4,5];
  11. // find() 查找数组中第一个符合条件的值
  12. // let num = arr.find(function(val,index,arr){
  13. // return val > 2;
  14. // });
  15. // console.log(num);
  16. // findIndex() 查找数组中第一个符合条件的索引
  17. // let index = arr.findIndex(function(val,index,arr){
  18. // return val > 2;
  19. // });
  20. // console.log(index);
  21. // for of 循环遍历数组中的每个元素
  22. // 语句方法 定义一个变量(接收数组中的每个元素) of 循环的数组
  23. // key() 方法返回数组的索引值
  24. // console.log(arr.keys());
  25. // for(let item of arr.keys()){
  26. // console.log(item);
  27. // }
  28. // value() 方法返回数组的值
  29. // for(let item of arr.values()){
  30. // console.log(item);
  31. // }
  32. // entries() 方法返回数组,数组包含索引值和值
  33. for(let item of arr.entries()){
  34. console.log(item);
  35. }
  36. </script>
  37. </body>
  38. </html>