I have two(2) arrays, beforeArray
& afterArray
const beforeArray = [
{
id:1,
name:'Alice'
},
{
id:2,
name:'Rabbit'
},
{
id:3,
name:'Queen'
},
{
id:4,
name:'King'
},
];
const afterArray = [
{
id:3,
name:'Queen'
},
];
I'm trying to get the difference of beforeArray
& afterArray
like this array below:
const currentArray = [
{
id:1,
name:'Alice'
},
{
id:2,
name:'Rabbit'
},
{
id:4,
name:'King'
},
];
I tried using these way but it only returns the value from let currentArray = [];
:
let currentArray = [];
await afterArray.map(async item => {
await beforeArray.filter(async find => {
if (item.id != find.id) {
await currentArray.map(async less => {
if (less.id == find.id) {
return;
} else {
currentArray = await [...currentArray, find];
}
});
}
})
console.log(currentArray);
I think it console.log(currentArray)
skips the await
....
How can I get the value from the awaited map and filter?