I have an array like
array = [
{ name: "john", tag: ["tag1", "tag2"] },
{ name: "doe", tag: ["tag2"] },
{ name: "jane", tag: ["tag2", "tag3"] }
];
I want to get a new array of objects which contain both "tag2" and "tag3", but not only "tag2" or both "tag1" and "tag2".
Result should be:
newArray = [{ name: "jane", tag: ["tag2", "tag3"] }];
I tried to do it using this process:
tags = ["tag2", "tag3"];
newArray = [];
tags.forEach(t => {
array.forEach(data => {
data.tag.forEach(item => {
if (item === t) {
newArray.push(data);
}
});
});
});
But I get all the items instead.