Golang check if slice key is present

Golang dose not let you check for a key directly but one method to achieve a similar effect is:

package main

import "fmt"

func main() {
var list []string

list = append(list, "first value")
list = append(list, "second value")
list = append(list, "third value")

if len(list) > 2 {
fmt.Println(list[2])
}
}

This is guaranty that list is 3 entries long, so key 2 exists.

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

©[current-year] KLEO Template a premium and multipurpose theme from Seventh Queen

Log in with your credentials

Forgot your details?