2
I have an array of users coming from a firebase database, I capture this array and run a map to capture some information, for example: mount a Cpf array, phone... This Cpf array for example I will use to compare with the Cpf that the client inserts at the time of its registration, to block the registration with an existing Cpf. I tried to use the for to do this, but the for goes through the list, when it reaches the equal condition (finds the repeated Cpf) it returns a true, but as it continues running the list it returns a false soon after, because the other cpfs are different from this.
I would like to know how I can perform this comparison until the condition is met? For example, I want to do the go until repeated Cpf is found, return me the true and I’ll handle the rest, what I’ve done so far was.
Here I do the map returning email, Cpf, phone, name...
this.pacientesSubscription = this.pacienteProvider.buscarPacientes().subscribe(data => {
this.cpfsCadastrados = data.map(result => {
return result.cpfSolicitante;
})
this.rgsCadastrados = data.map(result => {
return result.rgSolicitante;
})
this.emailsCadastrados = data.map(result => {
return result.emailSolicitante;
})
this.telefonesCadastrados = data.map(result => {
return result.telefone;
})
this.nomesCadastrados = data.map(result => {
return result.nomeSolicitante;
})
})
Then here I try to compare. What is nothing more, enter the list of names, if the name at the position i is equal to the one typed, return me a true in the startName variable. But it keeps going through the list and reaches the nameRepetido = false. Because the other names in the list are different.
consultaNome(){
for(let i = 0; i < this.nomesCadastrados.length; i++){
if(this.nomesCadastrados[i] === this.paciente.nomeSolicitante){
this.nomeRepetido = true;
alert('Já existe um cadastro com este nome na nossa plataforma, por favor corrija este campo');
} else {
this.nomeRepetido = false;
}
console.log(this.nomeRepetido);
}
}
Thanks man, your answer helped me solve here, I did as you said.
– Diego Estacho