基于对象属性删除数组元素我有一个类似于这样的对象数组:var myArray = [
{field: 'id', operator: 'eq', value: id},
{field: 'cStatus', operator: 'eq', value: cStatus},
{field: 'money', operator: 'eq', value: money}];如何根据其属性删除特定的属性?例如,如何删除以“Money”作为字段属性的数组对象?
3 回答

holdtom
TA贡献1805条经验 获得超10个赞
myArray = myArray.filter(function( obj ) { return obj.field !== 'money';});
filter
myArray

慕工程0101907
TA贡献1887条经验 获得超5个赞
myArray.splice(_.findIndex(myArray, function(item) { return item.value === 'money';}), 1);
更新
findIndex()方法返回数组中满足所提供的测试函数的第一个元素的索引。否则将返回-1。
myArray.splice(myArray.findIndex(myArray, function(item) { return item.value === 'money';}), 1);
添加回答
举报
0/150
提交
取消