<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>新增的几个循环方法</title> </head> <body> <script> let arr = [1,2,3,4]; for (const i in arr) { console.log(i);//0,1,2,3 } // for in 默认循环的是坐标 for (const item of arr) { console.log(item);//1,2,3,4 } // for of 默认循环的是每一项的内容 arr.forEach((item,i)=>{ console.log(item,i); }) </script> </body> </html>