Javascript - comparing two arrays by specific value and create a new array filled with matches -
please assume have 2 arrays filled objects this:
var arr1 = [{dog: "bark", cat: "meow", cow: "muh"}, {dog: "barking", cat: "meow", cow: "muhing"}] var arr2 = [{cat: "meow", dog2: "barked"}, {cow: "muhed", savage: "phew", cat: "meowed"}]
i wish such output:
var arr3 = [{dog: "bark", cat: "meow", cow: "muh", dog2: "barked"}]
i.e arr1
, arr2
have common key value pair in objects, it's cat: "meow"
, want these objects merged , pushed array, arr3
in case. possible? in advance!
please try this:
var _ = require('lodash'); var = [{a:1, b:2}]; var b = [{a:1, b:2, c:3}]; _.merge(a, b);
//output: {a:1, b:2, c:3}
see if works you.
Comments
Post a Comment