Compare two arrays of objects and get the objects based on ids
Use Map to reduce search complexity
Currently your method is rather complex at \$O(n^2)\$. The reason is that for each Id you iterate each item to locate the one with the Id you want.
You can use a Map to reduce the complexity. Map uses a hash to locate items, you can add each id to a map linking ids to each category.
Then just iterate the items array using the map to locate the correct category and add the item.
The result is achieved in a time complexity of \$O(n)\$.
The example shows how this can be implemented.


const categories = [{name: 'A', ids: [1, 2, 3]}, {name: 'B', ids: [4, 5, 6]}, {name: 'C', ids: [7, 8, 9]}]
const items = [{ id: 1, color: 'red'}, { id: 2, color: 'black'}, { id: 3, color: 'blue'}, { id: 4, color: 'yellow'}, { id: 5, color: 'green'}, { id: 6, color: 'pink'},{ id: 7, color: 'orange'}, { id: 8, color: 'white'}, { id: 9, color: 'teal'}];


function categorizeById(cats, items) {
    const idMap = new Map();
    const result = cats.map(cat =&gt; {
        const category = {name: cat.name, data: []};
        cat.ids.forEach(id =&gt; idMap.set(id, category));
        return category ;
    },[]);
    items.forEach(item =&gt; idMap.get(item.id).data.push({...item}));
    return result;
}
console.log(categorizeById(categories, items));