This language bar is your friend. Select your favorite languages!

Idiom #52 Check if map contains value

Determine whether map m contains an entry with value v, for some key.

Illustration
import std.algorithm;
m.byValue.canFind(v);
m.containsValue(v);
Map.values(m) |> Enum.member?(v)
func containsValue(m map[K]T, v T) bool {
	for _, x := range m {
		if x == v {
			return true
		}
	}
	return false
}
elem v (elems m)
import java.util.Map;
m.containsValue(v)
in_array($v,$m);
uses fgl;
m.IndexOfData(v) >= 0
print "Found it!" if exists $m{$v};
v in map.values()
m.include?(v)
use std::collections::BTreeMap;
let does_contain = m.values()
        .find(|&val| *val == v)
        .is_some();

Do you know the best way to do this in your language ?
New implementation...

Idiom created by

programming-idioms.org

Related idioms