我有一个从服务器接收到的对象产品数组。
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
日志:
->
符号是什么意思?看起来不像 JavaScript? - Steve Bennett