Skip few index in a for…of loop in Javascript
Topics related to client-side programming language.
Post questions and answers about JavaScript, Ajax, or jQuery codes and scripts.
-
Marius
- Posts:107
Skip few index in a for…of loop in Javascript
With the good old for loop in Javascript I can do things like:
Code: Select all
for (let i=0; i<bla.length; i+=2){
//...
}
So for every count, I can skip the index by doing a +2.
How can I do the same in the for…of loop to skip the index?
Code: Select all
for (const [i, element] of bla.entries()) {
//skip few index...
}
MarPlo
Posts:186
You may add an if() statement within the for...of loop, like in the following example (the original index is preserved).
Code: Select all
for (const [i, element] of bla.entries()) {
if (!(i % 2)) {
// do something here
}
}
Similar Topics
- Hour and Minutes togheter in Javascript
JavaScript - jQuery - Ajax
First post
Dear Coursesweb I can not find out how to add the hours + minutes togheter.
<SCRIPT LANGUAGE= JavaScript >
day = new Date()
hr =...
Last post
See and use the following example:
<script>
var day = new Date();
let hr = day.getHours();
let mn = day.getMinutes();
let se =...
- Display message to every minute in Javascript
JavaScript - jQuery - Ajax
First post
Hello,
On eatch minute from the current hour I wanna have an message
I can not find out how to complete
I hope to get something like this (code...
Last post
If you only want to display a message to every minute, just use the setInterval() function. It calls a function repeatedly, over and over again, at...