Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/423.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用Lodash删除对象(查找并删除)_Javascript_Lodash - Fatal编程技术网

Javascript 如何使用Lodash删除对象(查找并删除)

Javascript 如何使用Lodash删除对象(查找并删除),javascript,lodash,Javascript,Lodash,我想用Lodash删除uuid为xxx而不是xxx2的对象 我怎样才能用洛达斯制作这个 [ { "uuid": "xxx", "name": "test" }, { "uuid": "xxx2", "name": "test 2" } ] 我的实际代码: _.forEach(this.objs, (obj, index, collection) => { _.remove(obj, {u

我想用Lodash删除uuid为xxx而不是xxx2的对象

我怎样才能用洛达斯制作这个

[
    {
        "uuid": "xxx",
        "name": "test"
    },
    {
        "uuid": "xxx2",
        "name": "test 2"
    }
]
我的实际代码:

_.forEach(this.objs, (obj, index, collection) => {
   _.remove(obj, {uuid})
})

您可以使用
Array.prototype.filter()
来实现此目的

让arr=[
{
“uuid”:“xxx”,
“名称”:“测试”
},
{
“uuid”:“xxx2”,
“名称”:“测试2”
}
]
arr=arr.filter(e=>e.uuid!='xxx2');

控制台日志(arr)您可以使用
Array.prototype.filter()
来实现此目的

让arr=[
{
“uuid”:“xxx”,
“名称”:“测试”
},
{
“uuid”:“xxx2”,
“名称”:“测试2”
}
]
arr=arr.filter(e=>e.uuid!='xxx2');
控制台日志(arr)您可以使用简单的方法

var对象=[
{
“uuid”:“xxx”,
“名称”:“测试”
},
{
“uuid”:“xxx2”,
“名称”:“测试2”
}
];
_.remove(对象,o=>o.uuid=='xxx2');
console.log(对象)
您可以使用简单的方法

var对象=[
{
“uuid”:“xxx”,
“名称”:“测试”
},
{
“uuid”:“xxx2”,
“名称”:“测试2”
}
];
_.remove(对象,o=>o.uuid=='xxx2');
console.log(对象)

您可以使用filter
arr=arr.filter(({uuid}=>uuid!='xxx')可能存在的重复项有u.filter返回一个新数组或u.remove将其更改到位。使用loadash
.remove(arr,({uuid})=>uuid==='xxx')
您可以使用filter
arr=arr.filter({uuid}=>uuid!='xxx')可能存在的重复项有u.filter返回一个新数组或u.remove将其更改到位。使用loadash
.remove(arr,({uuid})=>uuid=='xxx')
您也可以使用
.remove(objects,{uuid:'xxx2')
@CélineMartin在我的回答中按
运行代码片段
按钮。或者给我你的预期输出?@mohamedabas这个,只返回我删除的元素,而不是没有这个对象的列表。。。我没有错。@CélineMartin对不起,你能为你的预期输出写一个例子吗?你可以把它放进去,你也可以使用
。.remove(对象,{uuid:'xxx2'})
@CélineMartin在我的回答中按
运行代码片段
按钮。或者给我你的预期输出?@mohamedabas这个,只返回我删除的元素,而不是没有这个对象的列表。。。我没有错。@CélineMartin对不起,你能为你的预期输出写一个例子吗?你可以把它放进去