How do I find the first occurrence of a particular value in a Javascript Map
? For example:
const m = new Map();
m.set("a", "b");
m.set("c", "d");
m.set("e", "f");
m.set("g", "f");
// Then I want to do something like this:
m.find_value((v) => v === "f");
Ideally it would return the key and value as a tuple (2-element array), i.e. ["e", "f"]
.
Obviously this is trivial to code manually with a for loop, but is there any neater built in way?