Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Immutable.js Map values to array

I am using the immutable Map from http://facebook.github.io/immutable-js/docs/#/Map

I need to get an array of the values out to pass to a backend service and I think I am missing something basic, how do I do it ?

I have tried :

mymap.valueSeq().toArray()

But I still get an immutable data structure back ?

For example :

var d = '[{"address":"10.0.35.118","cpus":4}]'; var sr = JSON.parse(d); var is = Immutable.fromJS(sr);  console.log(sr);  console.log(is.toArray()); console.log(is.valueSeq().toArray()); 

See this http://jsfiddle.net/3sjq148f/2/

The array that we get back from the immutable data structure seems to still be adorned with the immutable fields for each contained object. Is that to be expected ?

like image 229
LenW Avatar asked Oct 15 '15 12:10

LenW


People also ask

Is map Immutable JavaScript?

js provides many Persistent Immutable data structures including: List , Stack , Map , OrderedMap , Set , OrderedSet and Record .

Is map function Immutable?

Multiple iterations of the same Map will iterate in the same order. Map's keys can be of any type, and use Immutable.is to determine key equality.

What is Immutablejs?

Immutable. js is a library that supports an immutable data structure. It means that once created data cannot be changed. It makes maintaining immutable data structures easier and more efficient. The tool supports data structure like: List, Map, Set and also structures that are not implemented in .

What is toJS?

toJS() converts plain JS objects with a length property, in an Immutable collection, to an array (v4) #1438.


1 Answers

Just use someMap.toIndexedSeq().toArray() for getting an array of only values.

like image 84
Hüseyin Zengin Avatar answered Sep 24 '22 02:09

Hüseyin Zengin