I'm trying to do a loop that modifies an array and after completing the whole loop the idea is to execute some code with the modified array, but when I try to do it the code after the loop is executed before the array has been modified.
I wonder if there is a way to do it, like executing the loop synchronously.
I've tried using callbacks and async/await calls, but it didn't work for me.
for (m in muns) {
model.findAll({
...
})
.then((con) => {
if (con.length != 0) {
for (c of con) {
if (!(muns.includes(c.origen))) {
muns.push(c.origen)
}
if (!(muns.includes(c.destino))) {
muns.push(c.destino)
}
}
}
});
}
console.log(muns)
I Expected to get muns
array modified, but instead it hasn't change.