拉绳不工作

Lodash Pull not working

本文关键字:工作      更新时间:2023-09-26

如果我运行以下代码,长度不会改变:

console.log(files.length);
_.pull(files, [files[0], files[1]]);
console.log(files.length);

,其中files为Array对象。如果我直接从数组中构造它的第二个参数,那么pull不应该绝对找到要删除的匹配吗?

我不认为你应该传递你想'拉'的值数组。文档建议它们应该是单独的参数,像这样:

_.pull(files, files[0], files[1]);

https://lodash.com/docs拉

由于某种原因试图更改length属性或执行任何可能导致引擎隐式更改长度的操作,例如调用files。,将抛出RangeError

为什么不创建一个新的数组,使用without()来删除不需要的文件?

var newFiles = _.without(files, files[0], files[1]);