How to add element to the end of a slice in Go

1 Answer

0 votes
package main
  
import (
    "fmt"
)
  
func main() {
    slice := []int{4, 6, 12, 45, 98, 77, 32, 5, 1, 99, 100}
    val := 32
    
    fmt.Println(slice)
    
    slice = append(slice, val)
    
    fmt.Println(slice)
} 

   
 
/*
run:
  
[4 6 12 45 98 77 32 5 1 99 100]
[4 6 12 45 98 77 32 5 1 99 100 32]
  
*/

 



answered Aug 16, 2020 by avibootz
...