Hello I am making an for loop to get data from iframe. But the loop is too fast. How can i slow down this loop to execute every iteration in 50-100 ms or more?
for (let i = 113361978; i < 113371978; i++) {
fetch('https://vimeo.com/api/oembed.json?url=https://player.vimeo.com/video/' + i)
.then(res => res.json())
.then(
(json) => {
console.log(i);
if (json.author_name === 'Chuck Norris') {
document.write(`<iframe src="https://player.vimeo.com/video/${i}" width="640" height="640" frameborder="0" allowfullscreen=""></iframe>`);
}
}
)
}
I tried also using setInterval but then my i variable doesnt equal to result and display iframe with wrong id.
let i = 220316094;
function loop(){
fetch('https://vimeo.com/api/oembed.json?url=https://player.vimeo.com/video/' + i)
.then(res => res.json())
.then(
(json) => {
console.log(i);
if (json.author_name === 'Chuck Norris') {
document.write(`<iframe src="https://player.vimeo.com/video/${i}" width="640" height="640" frameborder="0" allowfullscreen=""></iframe>`);
}
}
).then(i++)
}
function loop2(){
setInterval(loop, 50);
}
loop2()