How to avoid find in map?

There is a better option and faster solution that will help me to solve this one?
Thanks

const transformedArray = firstArray.map((item) => ({
        ...item,
        param:
          secondArray.find((subItem) => subItem.groupId === item.groupId),
      }));

>Solution :

What about N+M instead of N*M.

const params = new Map();
secondArray.forEach(item => params.has(item.groupId) || params.set(item.groupId, item));

const transformedArray = firstArray.map((item) => ({
    ...item,
    param: params.get(item.groupId)
}));

Leave a Reply