const tags = [
{
id: 1,
name: 'one'
},
{
id: 2,
name: 'two'
},
{
id: 3,
name: 'three'
},
{
id: 4,
name: 'four'
}
]
const active = [
{
name: 'one'
},
{
name: 'four'
}
]
const result = tags.filter(n => active.some(m => m.name === n.name));
const result = tags.filter(function(n) {
return this.has(n.name);
}, new Set(active.map(n => n.name)));
const tagsObj = tags.reduce((acc, n) => (acc[n.name] = n, acc), {});
const result = active.reduce((acc, n) => ((n = tagsObj[n.name]) && acc.push(n), acc), []);