"how to do it correctly" does not explain very much about the problem you face.
Is there an error?
Is the array just left unchanged, where you expected to see a change?

The line of code...