Home > Enterprise >  How to get difference values between an array of values and array of object using lodash
How to get difference values between an array of values and array of object using lodash

Time:02-04

I have two array as

a1 = ['[email protected]','[email protected]','[email protected]'];
a2 = [{email: '[email protected]'},{email: '[email protected]'}];

Now I want to get difference between these two array mentioned above as

resultDifference = ['[email protected]'];

How to achieve this difference result by using lodash only.

CodePudding user response:

You should add what you have tried to your post

const a1 = ["[email protected]", "[email protected]", "[email protected]"];
const a2 = [{ email: "[email protected]" }, { email: "[email protected]" }];

const ans = _.difference(
  a1,
  a2.map((a) => a.email)
);
  •  Tags:  
  • Related