I am attempting to gather all similar data values into an array of objects. Here is my initial input:
var a = [{
name: "Foo",
id: "123",
data: ["65d4ze", "65h8914d"]
},
{
name: "Bar",
id: "321",
data: ["65d4ze", "894ver81"]
}
]
The desired result is:
["65d4ze"]
I have tried looping through the object to achieve this outcome, but I have become quite perplexed... I am unsure how to determine if the result exists in all data arrays.
var a = [{
name: "Foo",
id: "123",
data: ["65d4ze", "65h8914d"]
},
{
name: "Bar",
id: "321",
data: ["65d4ze", "894ver81"]
}
],
b = [],
c = []
a.forEach(function(object) {
b.push(object.data.map(function(val) {
return val;
})
);
});
console.log(b);