This question already has an answer here:
- Remove slice element within a for 1 answer
- How to remove element of struct array in loop in golang 4 answers
- Remove elements in slice 4 answers
var fields = []string{1,2,3,4,5,6,7,8,9}
for k, v := range fields {
if v % 2 == 0 {
fields = append(fields[:k], fields[k+1]...)
}
}
- it will be panic because the
k
will be bigger than fields length . - how to remove the right field quickly and use less memory ?
</div>