0
I have the following code :
search(evento){
this.str = evento.target.value;
console.log('str ',this.str)
this.cartoes.forEach(element => {
if(element.codigo.search(this.str) !== -1 && this.cartoesFiltro.length === 0){
this.cartoesFiltro.push({
idtag: element.idtag,
codigo: element.codigo,
alocada: element.alocada,
nome: element.nome
})
console.log('cartoesFiltro ',this.cartoesFiltro);
//this.idProcura = element.idtag;
//console.log('aqui',this.idProcura);
}
if(element.codigo.search(this.str) !== -1 && this.cartoesFiltro.length !== 0 ){
this.cartoesFiltro.forEach(dado => {
if (dado.idtag === element.idtag){
console.log('existe')
}
else{
this.cartoesFiltro.push({
idtag: element.idtag,
codigo: element.codigo,
alocada: element.alocada,
nome: element.nome
})
}
});
//this.cartoesFiltro = [];
//console.log('aqui ',this.cartoesFiltro)
}
if(element.codigo.search(this.str) === -1 && this.cartoesFiltro === 0){
console.log('nachou');
this.cartoesFiltro = [];
}
if (this.str === ''){
console.log('ndeu');
this.cartoesFiltro = [];
console.log('cartoesFiltro ',this.cartoesFiltro);
}
}
Theoretically it should search something in an array, and find itself inserted in a second array. But he’s inserting the same thing more than once, how can I fix it ?