skip to Main Content

Merge 2 array of objects with different properties – Javascript

I have 2 arrays of objects: array1 = [{"id":1,"cost":200,"qty":56},{"id":2,"cost":100,"qty":16}]; array2 = [{"id":1,"cost":200,"desc":"a good one"},{"id":2,"cost":100,"desc":"a bad one"},{"id":3,"cost":50,"desc":"an okay one"}]; I want to merge them so it looks like this: [{"id":1,"cost":200,"qty":56,"desc":"a good one"},{"id":2,"cost":100,"qty":16,"desc":"a bad one"}]; Please notice the new array has properties…

VIEW QUESTION
Back To Top
Search