Home Web Front-end JS Tutorial In-depth understanding of the loop statement for statement in javascript_javascript skills

In-depth understanding of the loop statement for statement in javascript_javascript skills

May 16, 2016 pm 04:53 PM
for statement loop statement

Loop statements are often used in program implementation, among which the for loop is found in most languages. In JavaScript, there are several different uses of for loops. Here are my understandings of each.

First type: (usually, loop to perform related operations)

Copy code The code is as follows:

var objA=document.getElementsByTagName("a");
var i,max;
for(i=0,max=objA.length;iobjA[i].onclick=function(){
alert(this.innerHTML);
}

}

loop, registering hyperlink tags in turn Click operation

The second type: (for objects, operating object content)
Copy code The code is as follows :

var person={name:'wmhello',age:'28'};
var tips=''; for(var obj in person){
tips =obj '-->' person[obj] 'n'

}

alert(tips)

The third type: (commonly used for arrays, for arrays Perform specific operations)
Copy code The code is as follows:

var num=[1,3 ,5];
var total=0;
num.forEach(function(e){
total =e;
});
alert(total);

This forEach loop works in firefox and chrome
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Learn Loop Structures: for, foreach, and while statements Learn Loop Structures: for, foreach, and while statements Jun 20, 2023 pm 06:51 PM

Learn loop structures: for, foreach, and while statements In programming, loop structures are essential because they allow the program to repeatedly execute a section of code, thereby saving time and amount of code. In programming languages ​​such as PHP, Java, and C#, there are three loop structures: for, foreach, and while statements. In this article, we will introduce these three loop structures respectively, as well as their application scenarios and some usage techniques in programming. for loop The for loop is one of the most basic loop structures.

How to solve Python loop statement error? How to solve Python loop statement error? Jun 25, 2023 am 10:15 AM

The Python loop statement is very basic but also very important. You can use it to repeatedly execute a piece of code until a certain condition is met. Commonly used loop statements in Python include for loops and while loops. Even though loop statements are very simple, you can still encounter various loop errors while writing code. In this article, I will discuss several common loop errors and their solutions. 1. Language Error Check for spelling errors and symbol errors such as missing colons and parentheses. In Python, these errors

Detailed explanation of loop statements in C++ Detailed explanation of loop statements in C++ Aug 22, 2023 am 11:52 AM

C++ is an efficient programming language with powerful functions and a wide range of applications. Loop statements are one of the most important parts of C++. C++ provides several loop statements to make it easier for programmers to iterate data. This article will introduce the loop statement in C++ in detail. 1. for loop A for loop is an iterative statement that allows programmers to easily perform a specified operation repeatedly. The basic syntax of a for loop is as follows: for(initialization;condi

How to use loop statement function in C++? How to use loop statement function in C++? Nov 18, 2023 pm 05:13 PM

How to use loop statement function in C++? C++ is an object-oriented programming language with powerful loop functions that help developers perform repetitive tasks more efficiently. The loop statement function can create a loop in the code to execute the same piece of code multiple times, thereby simplifying the programming process and improving the readability of the code. In C++, we use loop statement functions to perform different types of loops, including for loops, while loops, and do-while loops. different loop classes

How to use loop statements in Python? How to use loop statements in Python? Jun 03, 2023 pm 08:51 PM

Python is a high-level programming language that is widely used in fields such as data science, artificial intelligence, web development, and automation. The loop statement is one of the most basic control structures in Python programming, which allows a program to repeatedly execute a block of code until a termination condition is met. In this article we will introduce two types of loop statements in Python - for loop and while loop, and provide some examples to demonstrate their usage. 1. for loop statement The for loop statement in Python is used to traverse a

What loop statements are there in java? What loop statements are there in java? Jun 21, 2023 pm 03:42 PM

Java's loop statements: 1. while loop, the syntax is "while (Boolean expression) {loop body;}", the loop body is executed when the condition is true; 2. do-while loop, the syntax is "do{loop body; }while (Boolean expression);", even if the condition is not met, it will be executed at least once; 3. for loop, the syntax is "for (expression 1; expression 2; expression 3) {loop body;}"; expression Expression 1 is to assign a value to a variable, expression 2 is a loop condition, and expression 3 is to change the value of a variable.

Learn to use conditionals and loop statements in Golang Learn to use conditionals and loop statements in Golang Dec 23, 2023 pm 01:19 PM

To master conditional statements and loop statements in Golang, you need specific code examples. In Golang, conditional statements and loop statements are a very important part of the program. Conditional statements are used to determine the execution flow of the program, while loop statements are used to repeatedly execute a section of code. This article will introduce conditional statements and loop statements in Golang in detail and provide specific code examples. Conditional Statements Conditional statements are used to execute different blocks of code depending on whether a condition is true or false. In Golang, conditional statements include if statements, if-els

How to use loop structure in PHP programming? How to use loop structure in PHP programming? Jun 12, 2023 pm 01:09 PM

In PHP programming, the loop structure is a very important control flow structure. Through the loop structure, we can make the code repeatedly execute a specific block of code, which can be a statement or a group of statements. The loop structure allows us to solve some repetitive tasks with less code and can reduce the occurrence of code logic errors. This article will introduce how to use loop structures in PHP programming. for loop The for loop is one of the most used loop structures in PHP programming. As the name suggests, the for loop loops within a certain range.

See all articles