What is the best way to remove "nil" from slice of interface{} and generating a new slice of interface{}?
Slice := []interface{}{1, nil, "string", nil}
Nothing good comes to my mind ?
What is the best way to remove "nil" from slice of interface{} and generating a new slice of interface{}?
Slice := []interface{}{1, nil, "string", nil}
Nothing good comes to my mind ?
newSlice := make([]interface{}, 0, len(Slice))
for _, item := range Slice {
if item != nil {
newSlice = append(newSlice, item)
}
}