简体   繁体   中英

More than one operation on each parameter of the for loop in Javascript

Is there a syntax to include multiple initialization or final expression on a for loop in javascript?

For instance initialize two variables, or increment two variables.

I don't see anything about it on the MDN documentation .

I think this is what you're asking for....

for (var i = 0, a = 1; i < 10; i++, a += 2) {
    console.log(i, a);
}

output:

0 1
1 3
2 5
3 7
4 9
5 11
6 13
7 15
8 17
9 19

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM