1

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?

1
  • Have you tried to filter it? Commented Mar 9, 2016 at 16:39

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

0

After you map over the array you can do

Object.seal( yourMappedArrayObject );

That will make that object then immutable.

Object.seal

1 Comment

I don't think that's what he was asking.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.