jcalfee314 jcalfee314 - 10 months ago 67
Javascript Question

Searching an immutable JS Map

Can you please suggest the most efficient way to search Immutable.Map's values? I'm looking to return the first match.


I believe I should get a

and go from there. I'm trying to do something like this:

Immutable= require("immutable")
var keys = Immutable.Map()
var result = null
function(value) {
if(value == 2)
result = value
return result

I would like to stick with the Map data structure, it is used elsewhere in the code.


You can use .find:

var Immutable = require("immutable");
var map = Immutable.Map();
var m = map.set(1,2);
return m.find(function(val) {
    return value == 2;

You can use m.valueSeq().find as well.