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: 106
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
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
-
Repeat a step in a for loop in JS
JavaScript - jQuery - Ajax
First post
I have a for() loop like this one which shows what i want to do.
for(var i=0; i<15; i++) {
// Add data in html
// When data has a specified...
Last post
To achieve your goal you can add the if() condition within the loop, and check the values of your data.
If it has the specified value, sets the new...
-
Find item in array and set as first index
JavaScript - jQuery - Ajax
First post
Say I have the following array of persons:
const arr =
And I want to find a certain person (name) in this array, and put it as the first...
Last post
You could sort the array with the sort() method.
This approach moves all objects with the wanted 'name' to top.
const arr = ;
let first =...
-
SSEP index and edit search results data
Scripts from this website
First post
Hi,
The SSEP script seems to work.
last 2 questions:
1. If I update my website, do I have to re-index the whole domain or is there a option to...
Last post
The SSEP script is not suitable for a forum because the forum has dynamically content that can change very frequently.
SSEP has not option to edit...
-
Get id from url in javascript
JavaScript - jQuery - Ajax
First post
Last time you learnt me how to add an id from url to a javascript
but by this script it is not working what do I do wrong ????
<?php...
Last post
Maybe there is some mistake in other part of your script.
Check to see if there is any js error in browser console, F12.
What value it shows in...
-
Problem with value of $_GET from php to javascript
PHP - MySQL
First post
I found a script from: tutorialzine.com/2014/09/cute-file-browser-jquery-ajax-php
what I wanna use for my website.
But I can`t find out how to...
Last post
Thanks Chief for the support `it is working now`