Double indexing - wondering what's going on

Hi, I came upon this issue in one of my functions and wondering what’s going on in the background. I am trying to reassign some elements in an array, but this does not work when I use double indexing (see below for a simple example

y = [missing;3;1]
nonmis = y.!==missing;
y[nonmis][1] = 4

However y[nonmis][1] still returns 3. I have modified my code so this is not an issue but I am just curious why.

If I index an array in the second index I realized this returns not an Array but a view(::Array{Union{Missing,Float64},1}, [index]) so perhaps this is related.

First y[nonmis] creates a new array and copies the indexed data into it, then the first element of this new array is set to 4. Then the new array goes out of scope and the change is lost. If you want y to be changed you need the first indexing to return a reference instead of a copy, which either of these do:

(@view y[nonmis])[1] = 4
@views y[nonmis][1] = 4

great thank you!