JavaScript中常用的循环语句

JavaScript中常用的循环语句有: for, for-each,while,do-while

  1. for循环示例代码:
for(let i=0;i<10;i++){
  console.log(i);
}
  1. for-each循环示例代码:
const array = [1, 2, 3, 4, 5];

array.forEach((i) => {
  console.log(i);
});
  1. while循环示例代码:
let counter = 1;

while (counter <= 5) {
  console.log(counter);
}
  1. do-while循环示例代码:

let i = 1;
do {
    console.log(i);
    i++;
} while (i <= 100)

你可能感兴趣的:(系统示例代码,javascript,前端)