我对此代码的期望是[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