标准 for 循环for (let i = 0; i <h2> for...of 循环(遍历数组)</h2><pre class="brush:php;toolbar:false">const fruits = ['apple', 'banana', 'orange'];for (const fruit of fruits) { console.log(fruit);登录后复制 for...in 循环(迭代对象属性)const person = { name: 'john', age: 30, job: 'developer'};for (const key in person) { console.log(`${key}: ${person[key]}`);}登录后复制 foreach循环(数组方法)const numbers = [1, 2, 3, 4, 5];numbers.foreach((number, index) => { console.log(`index ${index}: ${number}`);});登录后复制 while 循环(严格来说不是 for 循环,但值得一提)let count = 0;while (count <p>这些示例演示了在 javascript 中进行迭代的各种方法,每种方法都适合不同的场景和数据结构。</p> 登录后复制以上就是JavaScript For 循环示例的详细内容,更多请关注我的其它相关文章!
标签:index,const,log,示例,JavaScript,循环 From: https://www.cnblogs.com/aow054/p/18423184