Curriculum Collections Iteration with range exercise 4 · mcq
Iteration with range
Range over a map produces TWO values per iteration: the key and
the value. Pick the idiomatic Go form for "for each entry of
prices, print key=value".
TypeScript:
``ts
for (const [k, v] of Object.entries(prices)) {
console.log(k, v);
}
``
TypeScript reference
About this theme
for i, v := range collection is the workhorse. Over a slice you get (index, value). Over a map you get (key, value). Over a string you get (byteIndex, rune). Over a channel you get just the value, with no index. Use _ to discard either side.