I make two api call and I need to compare the results and create a new array that contains only the values of the second call that are not equals to first
const listaRealmTrovata = async () => {
await axios.get(APICALL1)
.then((realmUserAttivi) => {
axios.get(APICALL2)
.then((realmAttivi) => {
realmUserAttivi.data.map((realmUserAttivo) => {
realmAttivi.data.filter((res) => {
if (realmUserAttivo.realm.id !== res.id) {
setListaRealm(previousListRealm => [...previousListRealm, { value: res.id, label: res.realmId }]);
}
})
})
})
})
};
In this way I obtain a list with with repeated values, because I compare each element of the first array each time with the elements of the second array
Example:
realmUserAttivi.data : [
0: {id:1}
1: {id:2}
3: {id:3}
]
realmAttivi.data : [
0: {id:1}
1: {id:5}
3: {id:3}
]
so the result that I would to obtain is:
listaRealm: [0: {id:5}] // the only one that isn't in equal in the two array.