javascript - Delete object from ImmutableJS List based upon property value -
what simplest way delete object list based on value of property?
i'm looking equivalent of $pull in mongodb.
my list looks simple this:
[{a: '1' , b: '1'},{a: '2' , b: '2'}]
and i'd remove array object property a set '1'. in mongodb, i'd this:
model.update({_id: getcorrectparentobj},{ $pull: {listideletefrom: { a: '1' } } },(err, result)=>{});
how can same result immutablejs?
you filter
immutable list:
var test = immutable.list.of(immutable.map({a: '1'}), immutable.map({a: '2'})); test = test.filter(function(item) { return item.get('a') !== '1' });
however, filter
on non-empty list
result different immutable list, may want check occurrence of {a: 1}
first:
if (test.some(function(item) { return item.get('a') === '1'; })) { test = test.filter(function(item) { return item.get('a') !== '1' }); }
Comments
Post a Comment