From the docs: Map#keys
I get the keys of a Map and loop through it to transform them into an array. Is there a one line code to cleanly convert these keys into an array?
You can use keySeq instead of keys, an IndexedSeq has toArray method:
var map = Immutable.fromJS({
  a: 1,
  b: 2,
  c: {
    d: "asdf"
  }
})
var arr = map.keySeq().toArray()
                        If you can use ES6:
var map = Immutable.fromJS({
  a: 1,
  b: 2,
  c: {
    d: "asdf"
  }
});
var [...arr] = map.keys();
console.log(arr); // ["a", "b", "c"]
Or
var arr = Array.from(map.keys());
console.log(arr); // ["a", "b", "c"]
                        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