5

I'm trying to use Immutable in a project with reactjs and flux.

Let's say I have a .js file with the code

console.log ( Immutable.Map({1: 2}).toString() )

I browserify this script and run it from the browser (Google Chrome), the result is:

"Map { "1": 2 }"

notice that the key, 1, is now a string, not a number.

If I try the same code directly in the console of the site http://facebook.github.io/immutable-js/ I get the correct result:

"Map { 1: 2 }"

Why is this happening and what can I do to get the correct result (key as number) in my script?

I'm using node v0.10.26, Browserify 5.12.0 and immutable 3.7.1

javier
  • 1,705
  • 2
  • 18
  • 24
  • 2
    I think objects keys are always string, check [this](http://stackoverflow.com/questions/6066846/keys-in-javascript-objects-can-only-be-strings) – Eugene Glova Apr 04 '15 at 21:03

1 Answers1

6

Giving Map an array of key value pairs seems to do the trick:

> Immutable.Map([[1, 2]]).toString()
'Map { 1: 2 }'

see https://facebook.github.io/immutable-js/docs/#/Map/Map for more info

brianjob
  • 360
  • 1
  • 9