Getting nested values in Immutable.js Getting nested values in Immutable.js javascript javascript

Getting nested values in Immutable.js


A map is simply a collection of keys with values. What you have is a map with the key categories, and the value {1: 'a', 2: 'b'}. The value does not automatically become an Immutable map just because you place it inside another map.

Now, the getIn() function will only "see" other Immutable.js maps. What you have in there is a regular ol' javascript object. If you just want to get the 1 value, you can just do:

var obj = Immutable.Map({categories: {1: 'a', 2: 'b'}});var output = obj.getIn(["categories"])[1];alert(output);
<script src="https://cdnjs.cloudflare.com/ajax/libs/immutable/3.8.1/immutable.min.js"></script>