typeover
curriculum

Curriculum Collections Iteration with range exercise 1 · mcq

Iteration with range

Translate the TS index-and-value loop to its idiomatic Go form. The Go range keyword over a slice yields TWO values per iteration — and they come out in a specific ORDER (i, v), NOT the TS forEach (v, i) order.

TypeScript reference
Pick the idiomatic Go translation

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.