我收到以下函数的意外标识符错误。
function merge (one, two) {
one.forEach(function(assign){
//////////this next line is throwing the error////////////
if (two.some(function(req) req.related == assign.rid)) {
if (one.some(function(iter) iter.rid == req.rid)) {
iter.quantity++;
} else {
one.push(req);
}
}
});
return one;
}
该函数旨在对对象数组进行操作。
最佳答案
您在 .some(function()...
{ }
function merge (one, two) {
one.forEach(function(assign){
if (two.some(function(req){ req.related == assign.rid})) {
// ^-- This one you missed
if (one.some(function(iter){ iter.rid == req.rid})) {
// ^-- This one you missed as well
iter.quantity++;
} else {
one.push(req);
}
}
});
return one;
}
关于javascript - javascript 中的意外标识符错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34390347/