I have a list in my firebase and I need to verify if item exist in list, I would like a simple check but my loop doesn’t work
verificaTitulo() {
let keepGoing = false;
this.voteService.getVotes()
.subscribe((res) => {
if(res == '') {
this.pegarTitulo.emit(this.titulo);
this.tituloVerificado = true;
keepGoing = true;
console.log('If to be empty');
} else {
if(!keepGoing) {
for(let i = 0; i < res.length; i++) {
if(res[i].titulo == this.titulo) {
console.log(res[i])
console.log('already exist')
keepGoing = true;
// break;
} else {
console.log('create');
keepGoing = true;
// break;
}
}
// keepGoing = false;
}
}
})
}
inside loop I have two conditions if exist (‘already exist’) else (‘create’)
In console I see this result, so the console show the two results already exist and creat, what’s wrong ?