I have an array of product objects that was retrieved from the server.
return response()->json(['products' => $products->toArray()]);
Here is a snapshot of the log:
https://i.sstatic.net/hAzpr.png
To extract the attributes from each product, which I believe to be an array-like object, I attempted to loop through using Array.prototype.forEach.call
this.products.forEach(product => {
console.log(product);
console.log(product.attributes);
Array.prototype.forEach.call(product.attributes, function(child) {
// The loop does not seem to work, as nothing is being output.
console.log(child);
});
});
Unfortunately, the looping mechanism for the array-like object appeared unsuccessful, resulting in no output even though the product.attributes
were not empty. Here is a glimpse into the log of product.attributes
: