Logo

Programming-Idioms

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

Idiom #329 Read value in a map

Assign to v the value stored in the map m for the key k.

Explain what happens if there is no entry for k in m.

v = m.get(k);
v := m[k]
v, ok := m[k]
v = m.get(k);
m.getOrDefault(k, null);
local v=m[k]
$v = $m{$k};
$v = $m{$k} // 'foobar';
v = m[k]
v = m.get(k, "default value")
v = m.get(k)
v = m[k]

New implementation...
< >
programming-idioms.org