There are several different uses of the For loop in JavaScript

Source: Internet
Author: User
Tags foreach

For loops are available in most languages. There are several different uses of the For loop in JavaScript, as described below

Loop statements are often used in program implementations, where for loops are available in most languages.    There are several different uses of the For loop in JavaScript, and here's what I understand separately.  The first: (Usually, cyclic execution of related operations) code is as follows: Var obja=document.getelementsbytagname ("a");  var I,max;  for (i=0,max=obja.length;i<max;i++) {obja[i].onclick=function () {alert (this.innerhtml);  }} loop, and then register the Hyperlink tab by clicking the second: (For objects, manipulating object content) The code is as follows: Var person={name: ' Wmhello ', Age: ' 28 '}; var tips= '; for (Var obj on person) {tips+=obj+ '--> ' +person[obj]+ ' n '} alert (Tips) The third: (commonly used in arrays, which perform specific operations on an array) 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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.