我想用 Lodash 删除 uuid 为 xxx 而不是 xxx2 的对象。
如何使用 Lodash 做到这一点?
[
{
"uuid": "xxx",
"name": "test"
},
{
"uuid": "xxx2",
"name": "test 2"
}
]
我的实际代码:
_.forEach(this.objs, (obj, index, collection) => {
_.remove(obj, {uuid})
})
最佳答案
您可以简单地使用_.remove方法。
var objects = [
{
"uuid": "xxx",
"name": "test"
},
{
"uuid": "xxx2",
"name": "test 2"
}
];
_.remove(objects, o => o.uuid === 'xxx2');
console.log(objects);
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.4/lodash.min.js"></script>
关于javascript - 如何使用 Lodash 删除对象(查找并删除),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47591797/