Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

383
Vistas
How to change variable during for-loop

I ran into a problem with a for-loop in js. Let me try to explain my issue.

For example, we have an array

let arr = [15, 29, 44];

also we have a for loop

for (let h = 1; h < 100; h +=10) {
 
}

I need to iterate over an array inside the loop, so when h goes bigger than array it continues from the value number.

In the end I should get values like: 10, 15, 25, 35, 44, 54...

I'm trying to make a double loop, but it confuses me.

My code:

for (let h = 1; h < 100; h +=10) {
 for (var i = 0; i < arr .length; i++) {
   if(i > h) {
h=i;    
}
}
}

Does there better way to do it?

UPD. Sorry, tha arry should be let array = [{'key': 15}, {'key':29}, {'key':44}];

Thanks

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You could take a single loop with a check if h is greater than a value from the array, then take this value instead.

const
    data = [{ key: 15 }, { key: 29 }, { key: 44 }],
    result = [];

for (let h = 10, i = 0; h < 100; h +=10) {
    if (h > data[i]?.key) h = data[i++].key;
    result.push(h);
}

console.log(...result);

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda