I have an array of object products that received from server.
return response()->json(['products' => $products->toArray()]);
Here is its log:
And I need to loop through it to get the product.attributes
that I think it's a array-like object, so I use Array.prototype.forEach.call
this.products.forEach(product => {
console.log(product);
console.log(product.attributes);
Array.prototype.forEach.call(product.attributes, function(child) {
// It seems the loop doesn't work, so nothing is printed out.
console.log(child);
});
});
But it seems the loop on array-like object didn't work, so nothing was printed out, even my product.attributes
wasn't empty. Here is product.attributes
log: