skip to Main Content

I have this array

const a1 = ["[email protected]", "[email protected]", "[email protected]"];

const b1 = [
    {
        "Name": "username",
        "Email": "[email protected]"
    },
    {
        "Name": "username2",
        "Email": "[email protected]"
    },
];

I want to get all email which does not exist in b1 and is there in a1

without object in array i’m able to check with filter

this.a1.filter(x => !b1.includes(x))

2

Answers


  1. const a1 = ["[email protected]", "[email protected]", "[email protected]"];
    
    const b1 = [
        {
            "Name": "username",
            "Email": "[email protected]"
        },
        {
            "Name": "username2",
            "Email": "[email protected]"
        },
    ];
    
    const emailsNotInB1 = a1.filter(email => !b1.some(obj => obj.Email === email));
    
    console.log(emailsNotInB1);
    
    Login or Signup to reply.
  2. // checks array
    const checkEmails = (emails) => {
      return emails.filter(email => !b1.some(obj => obj.Email === email));
    }
    
    // call
    console.log(checkEmails(a1));
    

    hope it helps!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search