Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140161

How to merge two arrays in JavaScript and remove the duplicate items?

$
0
0

I have two arrays

var array1 = [{firstName:'John', age:32, email:'xyz1@email.com'}, {firstName:'Jack', age:40, email:'xyz2@email.com'}];
var array2 = [{firstName:'Jen', age:29, email:'abc1@email.com'}, {firstName:'Jack', age:40, email:'xyz2@email.com'}];

I would like to merge the two arrays and get the below output

var array3 = [{firstName:'John', age:32, email:'xyz1@email.com'}, {firstName:'Jack', age:40, email:'xyz2@email.com'}, {firstName: 'Jen', age: 29, email: 'abc1@email.com'}];

Would like to know best way to merge two arrays in JavaScript so that I get only the unique items from each array?


Viewing all articles
Browse latest Browse all 140161

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>