I have two arrays of objects, and want to find the corresponding objects to modify the first array, like so:
const arr1 = [
{ order: 1, material: "b", qty: 4 },
{ order: 2, material: "f", qty: 7 },
{ order: 3, material: "a", qty: 8 },
];
const arr2 = [
{ order: 2, material: "f", sku: 45 },
{ order: 3, material: "a", sku: 32 },
{ order: 1, material: "b", sku: 65 },
];
Desired output:
arr1 = [
{ order: 1, material: "b", qty: 4, sku: 65 },
{ order: 2, material: "f", qty: 7, sku: 45 },
{ order: 3, material: "a", qty: 8, sku: 32 },
];
I'm guessing there are many ways to do this and I'd be grateful for any solution. I'm out of my depth on this one and don't know where to start other than multiple loops, which I can't get to work properly.