for (let i = 0; iFor...of Loop (Iterating over Arrays)
const fruits = ['apple', 'banana', 'orange']; for (const fruit of fruits) { console.log(fruit);For...in Loop (Iterating over Object Properties)
const person = { name: 'John', age: 30, job: 'Developer' }; for (const key in person) { console.log(`${key}: ${person[key]}`); }forEach Loop (Array Method)
const numbers = [1, 2, 3, 4, 5]; numbers.forEach((number, index) => { console.log(`Index ${index}: ${number}`); });While Loop (Not technically a for loop, but worth mentioning)
let count = 0; while (countThese examples demonstrate various ways to iterate in JavaScript, each suited for different scenarios and data structures.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3