I want to retrieve keys() from the following Immutable Map:
var map = Immutable.fromJS({"firstKey": null, "secondKey": null }); console.log(JSON.stringify(map.keys()));
I would expect the output:
["firstKey", "secondKey"]
However this outputs:
{"_type":0,"_stack":{"node":{"ownerID":{},"entries":[["firstKey",null],["secondKey",null]]},"index":0}}
How to do it properly?
JSFiddle link: https://jsfiddle.net/o04btr3j/57/
Although this question got answered a while ago, here is a little update:
ES6 Solution:
const [ ...keys ] = map.keys();
Pre ES6 Solution:
var keys = map.keySeq().toArray();
This is how ImmutableJS object looks like.
If you want to get:
["firstKey", "secondKey"]
You need to do:
console.log(map.keySeq().toArray())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With