born2net
born2net

Reputation: 24993

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

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

Upvotes: 15

Views: 11562

Answers (1)

hazardous
hazardous

Reputation: 10837

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.

Upvotes: 25

Related Questions