1

import {Map} from 'immutable'

let map1 = Map({a:1,b:{c:2,d:3,e:1});
let map2 = Map({c:100,d:400});

how do I get Map {a:1,b:{c:100,d:400,e:1}} by merging map1 and map2?

1 Answer 1

2

You can use immutable.js built in mergeIn function. You will have to tweak map1 slightly so that the nested Map is also an instance of Map

The following code does the job:

let map1 = Map({ a: 1, b: Map({ c: 2, d: 3, e: 1 })})
let map2 = Map({ c: 100, d: 400 })
let map3 = map1.mergeIn(['b'], map2)
Sign up to request clarification or add additional context in comments.

Comments

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.