Thursday, 2 May 2019

Go language: Append an element to a slice


‘append’ method is used to append an element to a slice.

Example
var vowels = []string{"a", "e", "i"}
vowels = append(vowels, "o")

App.go
package main

import "fmt"

func main() {

 var vowels = []string{"a", "e", "i"}

 vowels = append(vowels, "o")
 vowels = append(vowels, "u")

 fmt.Println(vowels)

}

Output
[a e i o u]



Previous                                                 Next                                                 Home

No comments:

Post a Comment