Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

I have two array as

a1 = ['test1@gmail.com','test2@gmail.com','test3@gmail.com'];
a2 = [{email: 'test1@gmail.com'},{email: 'test2@gmail.com'}];

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

resultDifference = ['test3@gmail.com'];

How to achieve this difference result by using lodash only.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You should add what you have tried to your post

const a1 = ["test1@gmail.com", "test2@gmail.com", "test3@gmail.com"];
const a2 = [{ email: "test1@gmail.com" }, { email: "test2@gmail.com" }];

const ans = _.difference(
  a1,
  a2.map((a) => a.email)
);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading