The code checks each variant within the variant array and displays all objects that match the condition or 'undefined' if not. However, in this code snippet, a new array is being created for each item like so:
[{id: 'something'}] [{id: 'something'}] [{id: 'something'}] [{id: 'something'}]
. The goal is to have all the results inside a single array:
[
{id: 'something'},
{id: 'something'},
{id: 'something'},
{id: 'something'}
]
const mynewarr = [];
const myimages = product_details.data.product.images;
for(var i = 0; i < product_details.data.product.variants.length; i++) {
const myvari = product_details.data.product.variants[i].image_id;
const real = myimages.find(imageid => imageid.id == myvari);
mynewarr.push(real);
}