How to delete an element from a Slice in Golang?
RemoveIndex function created to remove specific item from String slice.
Example
package main
import "fmt"
func main() {
var strSlice = []string{"India", "Canada", "Japan", "Germany", "Italy"}
fmt.Println(strSlice)
strSlice = RemoveIndex(strSlice, 3)
fmt.Println(strSlice)
}
func RemoveIndex(s []string, index int) []string {
return append(s[:index], s[index+1:]...)
}
Output
[India Canada Japan Germany Italy]
[India Canada Japan Italy]
Most Helpful This Week
Golang program for implementation of AVL Trees
Sierpinski Carpet in Go Programming Language
GO Program to Calculate Area of Rectangle and Square
How do you create an HTTP server in Go?
Example to use various String Functions in Go Language
GO Program to Find LCM and GCD of given two numbers
How do you set headers in an HTTP response in Go?
How do you handle HTTP server shutdown gracefully in Go?
How to convert Struct fields into Map String?
Assign Default Value for Struct Field