Delete an element in slice using append in GoLang
Original
- Memory, Renee
- 2018-04-12 09:43:00
- 6556
ZenTao: 15 years of dedication to building open source project management software
Download Now
Array [a b c]
Task: Delete the second element. Get [a c].
Steps:
package main import ( "fmt" ) //function used to delete the element func remove(s []string, i int) []string { return append(s[:i], s[i+1:]...) } func main() { s := []string{"a", "b", "c"} fmt.Println(s) s = remove(s, 1) fmt.Println(s) }
Done!
Write a Comment
Support
- Book a Demo
- Tech Forum
- GitHub
- SourceForge
About Us
- Company
- Privacy Policy
- Term of Use
- Blogs
- Partners
Contact Us
- Leave a Message
- Email Us: [email protected]