Summary
To check if a slice or array is empty in Golang, one can use the builtin len() function, such as len(slice) <= 0.
1
A nil slice declared as var s1
string has no underlying data array and points to nothing
2
, while an empty slice, declared as s2 :=
string{} or s3 := make(
string, 0) points to an empty, non-nil array.
2
Therefore, to check if a slice or array is empty, one should first check if it is nil.
3
According to