我希望使用 Lodash 删除,该对象使用uuid:xxx而非xxx2。
如何使用 Lodash 制作此内容?
[
{
"uuid": "xxx",
"name": "test"
},
{
"uuid": "xxx2",
"name": "test 2"
}
]
我的实际代码:
_.forEach(this.objs, (obj, index, collection) => {
_.remove(obj, {uuid})
})
答案 0 :(得分:2)
您可以简单地使用_.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>
&#13;
答案 1 :(得分:0)
您可以Array.prototype.filter()
使用
let arr = [
{
"uuid": "xxx",
"name": "test"
},
{
"uuid": "xxx2",
"name": "test 2"
}
]
arr = arr.filter(e => e.uuid != 'xxx2');
console.log(arr);
&#13;