typeover
curriculum

Curriculum Collections Iteration with range exercise 8 · fill-word

Iteration with range

Iterate over a map and print every key→value pair. Fill in the two range variables in the correct order. TypeScript: ``ts for (const [k, v] of Object.entries(prices)) { console.log(k, v); } ` Trap: TS .forEach((v, k) => ...)` puts value FIRST. Go's range is the OPPOSITE — KEY first, value second.

TypeScript reference
Fill the blanks →

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.