Given
array1 := []int{1, 3, 4, 5}
array2 := []int{2, 4, 6, 8}
I want to insert array2[2]
i.e 6
at array1[1]
i.e before 3
so that array1
becomes a slice of {1, 6, 3, 4, 5}
. How can I do it?
Most the techniques I read online involve using the :
operator but results in remaining elements being inserted as well. How can I append single values at an index in a slice?
question from:
https://stackoverflow.com/questions/46128016/insert-a-value-in-a-slice-at-a-given-index 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…