gpt4 book ai didi

javascript - javascript 中的意外标识符错误

转载 作者:行者123 更新时间:2023-12-01 02:46:07 24 4
gpt4 key购买 nike

我收到以下函数的意外标识符错误。

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com