我嵌套了第二个for循环,并尝试为一年中的所有52周创建wk1、wk2等数组键。然后将其添加到item对象中。
期望的结果:
item.wk1 = phpjs.amazon_ratings[i].wk1;
item.wk2 = phpjs.amazon_ratings[i].wk2;
etc...var i;
var j;
for (i = 0; i < phpjs.amazon_ratings.length; i++) {
// Create the item object
var item = {};
// Add default array keys `sku`, and their values from the `amazon_ratings` array as we loop through each item.
item.sku = phpjs.amazon_ratings[i].sku;
item.asin = phpjs.amazon_ratings[i].asin;
item.current_week_rating = phpjs.amazon_ratings[i].rating;
item.total_ratings = phpjs.amazon_ratings[i].ratings_total;
item.category = phpjs.amazon_ratings[i].category;
// Loop 52 times and create array keys such as: WK1, WK2, WK3
for (j = 1; j < 53; j++) {
item.wk[j] = phpjs.amazon_ratings[i].wk[j];
}
// Add it to the array
tabledata.push( item );
}然而,它失败的原因是:Uncaught TypeError: Cannot set property '1' of undefined
发布于 2021-03-17 21:21:23
它应该是项目‘’wk‘+ j。
记住,一年没有52个星期。你必须每年检查一次。
https://stackoverflow.com/questions/66673920
复制相似问题