Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

immutable.js get keys from map/hash

Tags:

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/

like image 510
knagode Avatar asked Feb 25 '16 09:02

knagode


Video Answer


2 Answers

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(); 
like image 147
lumio Avatar answered Oct 04 '22 16:10

lumio


This is how ImmutableJS object looks like.

If you want to get:

["firstKey", "secondKey"] 

You need to do:

console.log(map.keySeq().toArray()) 
like image 22
Sagi Medina Avatar answered Oct 04 '22 16:10

Sagi Medina