Compare list of array to object javascript

I try to check from list of array element that same to as id object property then return (a) each array element as (tag) name object property to new element in dom

a= [28,32],
   [28,32,56]

b = {id:28, name:action},
    {id:32, name:horror},
    {id:56, name:comedy},

Result should be

Action horror


----------


Action horror comedy

Answer

You can use:

const a = [
    [28,32],
    [28,32,56]
];

const b = [
    {id:28, name:'action'},
    {id:32, name:'horror'},
    {id:56, name:'comedy'},
];

const data = a.map(item => item.map(id => b.filter(bItem => bItem.id === id).map(item => item.name)).join(' '));
console.log(data);