1
I have a function (in Javascript) that compares 2 arrays:
let diferencas = [];
let numD = 0;
for (let a = 0; a < dados.length; a++) {
if (dados[a].idEmail === results[a].idEmail) {
console.log('Repetido!')
} else {
numD++;
diferencas.push(dados[a]);
}
}
console.log('Diferenças encontradas: ' + numD)
console.log(diferencas)
The 2 arrays are composed in their first 8 positions by identical objects, with the array results
has only 8 positions as it comes from a query to Mongodb and the array dados
has 9 positions as it comes from a query to the email provider and comes with newer emails.
My problem is: How Do I Pick Up Those Over Positions in the Array dados
??
That example of object arrays also brings only the difference independent of the order of the objects??
– LeonardoEbert
@Leonardoebert Yes, I just exemplified with the string array to be simpler.
– Isac
I’m doing some tests here, but he’s not identifying the differences... I’ll put all the code in a jsfiddle and I’ll send you the link
– LeonardoEbert
Here is the entire code: https://jsfiddle.net/70ebprun/ ...
– LeonardoEbert
The mapping has to be adjusted to your example, of
const dados2 = dados.map(x => x.email);
forconst dados2 = dados.map(x => x.idEmail);
. Watch out for the difference between.email
for.idEmail
. I in response exemplified with fieldemail
to make it clearer to the reader– Isac
Kkkkkkk, I didn’t see this difference Now you found 3 differences... Thank you @Isac, you gave the perfect solution to my problem
– LeonardoEbert
I will only need now to adapt to save all the data of the objects in the database
– LeonardoEbert
@Leonardoebert I edited also for that detail. But would have to remap again with
map
to have the differences in object formatlet diferencasObj = diferencas.map(x => dados[dados2.indexOf(x)]);
– Isac
That your latest edition worked perfectly too, now just save the different objects in the database
– LeonardoEbert