<分区>
我有一组从服务器接收到的对象产品。
return response()->json(['products' => $products->toArray()]);
这是它的日志:
我需要遍历它来获取 product.attributes
我认为它是一个类似数组的对象,所以我使用 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);
});
});
但似乎类数组对象上的循环不起作用,所以什么也没有打印出来,甚至我的 product.attributes
也不为空。这是 product.attributes
日志: