I have two arrays of objects. I need to loop through the first array and append each object of the second array to each object of the first array.
First array:
const productsArray = [
{Name: 'product1', SKU: 'sku1'},
{Name: 'product2', SKU: 'sku2'},
{Name: 'product3', SKU: 'sku3'}
];
Second Array:
const quantitiesArray = [
{Quantity: 100},
{Quantity: 300},
{Quantity: 600}
];
Desired Outcome:
const newProductsArray = [
{Name: 'product1', SKU: 'sku1', Quantity: 100},
{Name: 'product2', SKU: 'sku2', Quantity: 300},
{Name: 'product3', SKU: 'sku3', Quantity: 600}
]
There will always be the same amount of objects in each array.
Object.assign()?{ ...productsArray[i], ...quantitiesArray[i] };P.S.: Please check out JavaScriptSpread syntax (...)to understand more about...objectusage. Here