Remove and adding elements to array in GO lang

For the output array you need to use append or allocate it with an initial capacity to match the size of input.

// before the loop
output := make([]string, len(input))

would be my recommendation because append causes a bunch of needless reallocations and you already know what capacity you need since it’s based on the input.

The other thing would be:

output = append(output, input[index])

But like I said, from what I’ve observed append grows the initial capacity exponentially. This will be base 2 if you haven’t specified anything which means you’re going to be doing several unneeded reallocations before reaching the desired capacity.

Leave a Comment

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