2825 explained code solutions for 75 technologies


golangHow to copy slice elements


package main

import "fmt"

func main() {
	s1 := []int{1, 2, 3}
	s2 := []int{4, 5}
  copy(s1, s2)
}ctrl + c
s1 := []int{1, 2, 3}

first slice to copy items to

s2 := []int{4, 5}

second slice to copy items from

copy(s1, s2)

copies elements from s2 slice to s1 slice