As lyyons pointed out in the comments, more idiomatic and lodashy way to do this would be to use _.remove
, like this
_.remove(obj.subTopics, {
subTopicId: stToDelete
});
Apart from that, you can pass a predicate function whose result will be used to determine if the current element has to be removed or not.
_.remove(obj.subTopics, function(currentObject) {
return currentObject.subTopicId === stToDelete;
});
Alternatively, you can create a new array by filtering the old one with _.filter
and assign it to the same object, like this
obj.subTopics = _.filter(obj.subTopics, function(currentObject) {
return currentObject.subTopicId !== stToDelete;
});
Or
obj.subTopics = _.filter(obj.subTopics, {subTopicId: stToKeep});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…