I have 2 array of objects:
const arr1 = [
{
"id": "1"
},
{
"id": "4"
},
{
"id": "7"
},
{
"id": "5"
}
]
const arr2 = [
{
"id": "1"
},
{
"id": "5"
}
]
I want to get those id
which does not exists in arr2
.
Expected response is:
[ "4", "7"]
What I have tried so far is:
let result = [];
for(m in arr1){
for(n in arr2){
if(arr1[m].id == arr1[n].id)
result.push(arr1[m]);
}
}
My solution is not returning the correct result, also I need to acheive this with the best possible practice and standards using Typescript.
Here is a playground that I created: