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

Idiom #51 Check if map contains key

Determine whether map m contains an entry for key k

Illustration
import qualified Data.Map.Strict as Map
Map.member k m
(/=Nothing) (lookup k m)
#include <map>
bool key_exists = m.find(k) != m.end();
if (k in m) { }
m.containsKey(k)
Map.has_key?(m, k)
maps:is_key(K, M).
_, ok := m[k]
k in m
import java.util.Map;
m.containsKey(k)
m[k] ~= nil
array_key_exists($k, $m)
uses fgl, classes;
m.IndexOf(k) >= 0
exists $m->{$k}
k in m
m.has_key?(k)
m.key?(k)
m.include?(k)
use std::collections::HashMap;
m.contains_key(&k)
(assoc k m)

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

Idiom created by

programming-idioms.org

Related idioms