typeover
curriculum

Curriculum Collections Iteration with range exercise 3 · mcq

Iteration with range

Now flip exercise 2 around: you want ONLY the index, no value. Pick the idiomatic Go form. TypeScript: ``ts for (let i = 0; i < items.length; i++) { console.log(i); } `` This is the form that bites exercise 2's trap-believers in reverse: when you DO want just the index, the one-value form is the RIGHT answer.

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.