Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the first key (not value) of immutable.js map?

Tags:

immutable.js

How to get the first key (not value) of immutable.js map?

basically myMap.first() will return the value, but I am interested in the key...

I can do a forEach and store first, but must be a better way!

didn't see it in the docs, prob missing it... :/

tx

Sean

like image 614
born2net Avatar asked Mar 18 '16 16:03

born2net


1 Answers

Do this -

var firstKey = map.keySeq().first();

Explanation - Get me a lazy sequence of keys of this map, then resolve the first key. Alternatively you can use keys() method which returns plain old ES6 iterator. It will be less performant though.

like image 89
hazardous Avatar answered Sep 21 '22 18:09

hazardous