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?