Reputation: 367
So I have a function like this
myNewMap = oldMap.map((check) => {
if (check.get('_id') === against.get('_id')) return check;
});
The only problem is myNewMap is the same size as the oldMap (which makes sense), but is there a way to stop this, or do I need a different approach?
Upvotes: 1
Views: 509
Reputation: 1520
After you map over the array you can do
Object.seal( yourMappedArrayObject );
That will make that object then immutable.
Upvotes: 0
Reputation: 23502
I think you want filter
myNewMap = oldMap.filter((check) => {
return check.get('_id') === against.get('_id');
});
Or even shorter:
myNewMap = oldMap.filter(check => check.get('_id') === against.get('_id'));
This will return a new Map
with only the values that meet the predicate.
Upvotes: 3