如果我有这样的代码:
QB_list.x.forEach(pushElementsQB)
function pushElementsQB(element, index, array)
{
rows.push([element, QB_list.y[index], "QB: " + QB_list.text[index], null, null, null, null]);
}
有没有办法在我的回调中指定 rows 变量?我是 javascript 新手,正在查看 spec这次对我不起作用:/
最佳答案
为什么不直接使用 map
?
var rows = QB_list.x.map(pushElementsQB);
function pushElementsQB(element, index, array)
{
return [element, QB_list.y[index], "QB: " + QB_list.text[index], null, null, null, null];
}
map
本质上是一个forEach
,它返回一个Array
。
关于javascript - 在 Array.prototype 中为 "for each"循环传递参数的语法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34318684/