0

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:

https://jsfiddle.net/u7txv5bz/

CodePro
  • 21
  • 2
  • See [Array filtering using Typescript](/q/74445352/4642212). – Sebastian Simon Nov 15 '22 at 13:12
  • There is no difference to usual JS or ES6. Check out suitable solutions here: https://stackoverflow.com/questions/1187518/how-to-get-the-difference-between-two-arrays-in-javascript – MS1 Nov 15 '22 at 13:14

0 Answers0