JSFiddle - React, Tailwind, and code Playground

by ppgab

JavaScript

function timeout(x){
 return new Promise( resolve => {
  setTimeout( () => {
  	return resolve(x);
  },x)
 })
}

const promises = [];
const results = [];
//First loop, array creation
for (let i = 0; i < 20; i++) {
  const promise = timeout(1000/((i*10)+1)).then(x => 
  results[i] = {
    index: i,
    timeout: x
  });
  promises.push(promise);
}
Promise.all(promises).then(() => {
  console.log(results);
});