Home > Web Front-end > JS Tutorial > There are several ways of for loop in js

There are several ways of for loop in js

下次还敢
Release: 2024-05-01 07:42:13
Original
952 people have browsed it

Types of for loops in JavaScript

In JavaScript, there are three types of for loops:

1. Basic for loop

Syntax:

<code>for (initialization; condition; increment/decrement) {
  // 循环体
}</code>
Copy after login
  • initialization: Initialization operation at the beginning of the loop.
  • condition: The condition that determines whether the loop continues. If the condition is false, the loop will be exited.
  • increment/decrement: The operation performed after each loop iteration. Used to update loop variables.

2. for...in loop

Syntax:

<code>for (variable in object) {
  // 循环体
}</code>
Copy after login
  • variable:Use Variable for the key of the iterated object.
  • object: The object to be iterated. The object can be an object or an array.

3. for...of loop

Syntax:

<code>for (variable of iterable) {
  // 循环体
}</code>
Copy after login
  • variable:Use A variable used to iterate over the elements in an iterable object (such as an array).
  • iterable: Iterable object. The object can be an array, string, or other data structure that supports iteration.

The above is the detailed content of There are several ways of for loop in js. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template