I have an object and an array. The object looks like this.
const saleProducts = {
category: "Books",
product_skus: [
"14003696",
"14003915",
"14003699",
"14003698",
"14003697",
"14003917",
],
};
The array has several objects inside and looks something like this:
const productDetails = [
{
_id: "618182229285e8d8f86be2d9b3",
name: "JS for Dummies",
description:
"Learning Manual",
category: "books",
sku: "14003696",
price: {
amount: 20
},
images: [
"https://uri1.png",
"https://uri2.png",
],
}
As you can see, the 'sku' in the array (bookDetails) matches one of the skus in 'saleProducts'. So I would like to replace the sku with the object that has all the details. In the end, I would like the 'saleProducts' to look like this:
const saleProducts = {
category: "Books",
product_skus: [
{
_id: "618182229285e8d8f86be2d9b3",
name: "JS for Dummies",
description:
"Learning Manual",
category: "books",
sku: "14003696",
price: {
amount: 20
},
images: [
"https://uri1.png",
"https://uri2.png",
],
]
} // ... etc. replacing each sku with the full details.
what is the simplest way to do this?