我對此代碼的期望是[1, 2, 5, 6, 7, 8, 9]
。結果是[7, 8, 9]
。我的錯誤在哪裏? Jsfiddle for this。謝謝。Lodash懶惰鏈不適合我
var ar = [1, 2, 3, 4, 5, 6],
arWrapper = _(ar),
removedTypes = [3, 4],
addedTypes = [7, 8, 9];
_.each(removedTypes, function (removedType) {
arWrapper = arWrapper.remove(function (type) {
return type === removedType;
});
});
_.each(addedTypes, function (addedType) {
arWrapper = arWrapper.push(addedType);
});
console.log("%O", arWrapper.value());
'arWrapper.remove'返回一個新的數組。不是Lodash對象。 – cgTag
@MathewFoscarini未鏈時 – zerkms