Answers for "iterate through slice golang"

Go
1

golang iterate through slice

var slice = []string{"Apple", "Orange", "Kiwi"}
for index, sliceItem := range slice { // You can omit index or sliceItem with a _
  fmt.Println("Index in slice:", index)
  fmt.Println("Fruit:", sliceItem)
}
Posted by: Guest on June-12-2020
0

golang iterate reverse slice

s := []int{5, 4, 3, 2, 1}
for i := len(s)-1; i >= 0; i-- {
   fmt.Println(s[i])
}
Posted by: Guest on August-20-2020
0

iterate over struct slice golang

for i, x := range p.Fruits
Posted by: Guest on March-09-2020

Browse Popular Code Answers by Language