You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
funcmain() {
varmmap[int]intv, ok:=m[0] // v = 0, ok = false
}
Issue: Slices and Arrays out of range access
funcmain() {
i:=0vars []intv:=s[i] // panic: runtime error: index out of range [0] with length 0a:= [0]int{}
v=a[i] // panic: runtime error: index out of range [0] with length 0
}
Solution: Use Maps two-value assignment approach for Slices and Arrays
funcmain() {
i:=0vars []intv, ok:=s[i] // v = 0, ok = falsea:= [0]int{}
v, ok=a[0] // v = 0, ok = false
}