The funny thing is that I knew it, but wrote `for v := range array` anyway at least a few times! My point is, it's not very intuitive. Thankfully, the compiler catches that, unless it's `[]int`.
The idea is it's `for k := range object` to iterate over the keys, and `for k, v := range object` to iterate over the keys and values, whether the object is a slice, array, map or string. The only exceptional case is a channel, which has no indices/keys.
Comments
The funny thing is that I knew it, but wrote `for v := range array` anyway at least a few times! My point is, it's not very intuitive. Thankfully, the compiler catches that, unless it's `[]int`.
The idea is it's `for k := range object` to iterate over the keys, and `for k, v := range object` to iterate over the keys and values, whether the object is a slice, array, map or string. The only exceptional case is a channel, which has no indices/keys.
It does make perfect sense, just goes against muscle memory from years of Python coding :)