| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
- <script>
- let arr = [1,2,3,4,5];
- // find() 查找数组中第一个符合条件的值
- // let num = arr.find(function(val,index,arr){
- // return val > 2;
- // });
- // console.log(num);
- // findIndex() 查找数组中第一个符合条件的索引
- // let index = arr.findIndex(function(val,index,arr){
- // return val > 2;
- // });
- // console.log(index);
- // for of 循环遍历数组中的每个元素
- // 语句方法 定义一个变量(接收数组中的每个元素) of 循环的数组
- // key() 方法返回数组的索引值
- // console.log(arr.keys());
- // for(let item of arr.keys()){
- // console.log(item);
- // }
- // value() 方法返回数组的值
- // for(let item of arr.values()){
- // console.log(item);
- // }
- // entries() 方法返回数组,数组包含索引值和值
- for(let item of arr.entries()){
- console.log(item);
- }
- </script>
- </body>
- </html>
|