How to create an empty Slice in Golang?
To declare the type for a variable that holds a slice, use an empty pair of square brackets, followed by the type of elements the slice will hold.
Example
package main
import (
"fmt"
"reflect"
)
func main() {
var intSlice []int
var strSlice []string
fmt.Println(reflect.ValueOf(intSlice).Kind())
fmt.Println(reflect.ValueOf(strSlice).Kind())
}
Output
slice
slice
Most Helpful This Week
Illustration of Cigarette Smokers Problem in Golang
How do you create an HTTP client in Go?
Program to print pyramid using numbers
How to read current directory using Readdir?
Contains, ContainsAny, Count and EqualFold string functions in Go Language
Multiple-value <function> in single-value context error in Golang