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
Top 20 Most Popular Cryptocurrencies To Watch In 2024
Web Application to read and write JSON data in JSON File
Program in Go language to Find Largest Element of an Array
Example: How to use ReadFull from IO Package in Golang?
Golang program for implementation of Pancake Sort
How do you handle HTTP server shutdown gracefully in Go?