Can someone please provide an explanation on how the copy method with slices is used…
I want to delete a specific index of a slice… and then insert something bask into the slice, in that exact index…
I know how I would do it all, other than how i would move everything after that specific index over one… and then add something else in its place. This is to simulate the entry in the slice being edited…
Hope someone can help
The below code removes it and i need to append back to the slice, in place of ‘oldindex’…
for i, va := range data[k] {
if i == vi {
toedit = true
oldindex = i
}
if toedit {
if len(data[k])-1 == i {
data[k] = data[k][:i]
} else {
data[k] = append(data[k][:i], data[k][i+1:]...)
}
//append back to the index we just removed...
break
}
}
So if we have this slice originally:
[1, 2, 3, 4, 5, 6]
I want to delete index 2 and replace it with the value given in a POST request… lets say the new value was 10, it would look like this
[1, 2, 10, 4, 5, 6]
Hopefully that’s a little more clear