How do you convert a slice into an array?

The built in method copy will only copy a slice to a slice NOT a slice to an array.

You must trick copy into thinking the array is a slice

copy(varLead.Magic[:], someSlice[0:4])

Or use a for loop to do the copy:

for index, b := range someSlice {

    varLead.Magic[index] = b

}

Or do as zupa has done using literals. I have added onto their working example.

Go Playground

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)