How to Create an Empty Slice in Golang


If you would like to create an empty slice in Go, then you can do the following:

Option 1 – Initialize an Empty Slice in Go

package main

import "fmt"

func main() {
    b := []string{}
    fmt.Println(b == nil)
}

Option 2 – Using make()

package main

import "fmt"

func main() {
    c := make([]string, 0)
    fmt.Println(c == nil)
}