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

223
Vistas
Remove object from array after being used in foreach function

Goodmorning,

I would like to remove an object from an array after it is used in a forEach loop. And then the foreach loop should continue with the next object left in the array.

However right now it runs the function for the first object, then I remove this first object and then the function stops running.

This is my script:

function test() {
  // Create array with id's of mailings to get from database
  var allAutomations = [
    {"id": "52"},
    {"id": "72"}
  ] 

  allAutomations.forEach(function(automation, index) {

    var a = 1;
    while (a <= 10) {
      console.log(a);
      a++
    }

    allAutomations.splice(index, 1);

    console.log(allAutomations);
          
  });
}

test();

As you can see in console at removing the current object works, but after that it should run the while loop for the one with id '72' again.

Anybody knows how to fix this?

about 4 years ago · Santiago Trujillo
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