How to get through an immutable card of immutable cards?

I have an immutable map card.

let mapOfMaps = Immutable.fromJS({
    'abc': {
         id: 1
         type: 'request'
    },
    'def': {
        id: 2
        type: 'response'
    },
    'ghi': {
        type: cancel'
    },
    'jkl': {
        type: 'edit'
    }
});

How can I

  • go through mapOfMaps and get all the keys to print them?
  • scroll mapOfMaps keys to get all key contents?

I have no way to switch to the List at this point.

I do not know how to scroll keys.

+14
source share
2 answers

Using the keySeq()/ method, valueSeq()you get a sequence of keys / values. Then you can repeat it, for example with forEach():

let mapOfMaps = Immutable.fromJS({
    abc: {
         id: 1,
         type: 'request'
    },
    def: {
        id: 2,
        type: 'response'
    },
    ghi: {
        type: 'cancel'
    },
    jkl: {
        type: 'edit'
    }
});

// iterate keys
mapOfMaps.keySeq().forEach(k => console.log(k));

// iterate values
mapOfMaps.valueSeq().forEach(v => console.log(v));

Alternatively, you can iterate in a single loop with entrySeq():

mapOfMaps.entrySeq().forEach(e => console.log(`key: ${e[0]}, value: ${e[1]}`));
+34
source

: , for. for break; .

//Iterating over key:value pair in Immutable JS map object.

for(let [key, value] of mapOfMaps) {
       console.log(key, value)

}
+1

Source: https://habr.com/ru/post/1660125/


All Articles