10 examples of 'golang remove from slice' in Go

Every line of 'golang remove from slice' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Go code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
210func removeFromSlice(slice []Player, index int) []Player {
211 return append(slice[:index], slice[index+1:]...)
212}
51func remove(slice []string, i int) []string {
52 return append(slice[:i], slice[i+1:]...)
53}
173func remove(array []exchange.Order, i int) []exchange.Order {
174 if len(array) == 1 {
175 return array[:0]
176 } else if len(array) < 1 {
177 return array
178 }
179
180 array[len(array)-1], array[i] = array[i], array[len(array)-1]
181 return array[:len(array)-1]
182}
70func remove(s []*pipe, i int) []*pipe {
71 s[i] = s[len(s)-1]
72 return s[:len(s)-1]
73}
159func RemoveString(slice []string, s string) []string {
160 result := []string{}
161 for _, elem := range slice {
162 if elem != s {
163 result = append(result, elem)
164 }
165 }
166 return result
167}
354func removeStringElement(slice []string, s int) []string {
355 return append(slice[:s], slice[s+1:]...)
356}
15func removeElementFromSlice(elements []string, index int) []string {
16 return append(elements[:index], elements[index+1:]...)
17}
173func RemoveFromSlice(s []string, target string) []string {
174 for i := len(s) - 1; i >= 0; i-- {
175 if s[i] == target {
176 s = append(s[:i], s[i+1:]...)
177 }
178 }
179 return s
180}
56func DeleteSliceElement(slice interface{}, idx int) interface{} {
57 return DeleteSliceElementVal(reflect.ValueOf(slice), idx).Interface()
58}
270func byteSliceRemove(text []byte, from, to int) []byte {
271 size := to - from
272 copy(text[from:], text[to:])
273 text = text[:len(text)-size]
274 return text
275}

Related snippets