Forum Discussion

joetesta's avatar
joetesta
Roku Guru
13 years ago

array pass by value?

Hello -

I have an array (of shows) and I'm trying to create a parallel array that has one field different (no show description in 2nd array). So far whatever I try has the effect of altering both arrays. I tried setting newArray = oldArray, then when I modify the elements of newArray it also affects oldArray. I also tried looping over oldArray and Push'ing the elements to newArray, then loop over newArray and modify the field. Unfortunately oldArray's fields were also modified. It seems like there must be a way to do this without modifying the oldArray?

tyvmia

3 Replies

  • thanks destruk! I think it happens because it's an array of objects; & I think i'd have to push the inner values of each object, rather than just pushing the objects themselves. But that's just my theory, i didn't go so far as to actually test that yet.
    The goal is we want to hide the descriptions on the grid view but have them available on the detail view. The only way I could think to do this is to have parallel show lists, one with blank descriptions. I wonder if there's any other way to customize the grid view display...
  • OK i went that route, create the new object and push the values in, then push the object onto the new array. Now it works, original array is unmodified. Rather than double the server requests for it. thanks!
  • "TheEndless" wrote:
    A quick array copy can be achieved by appending to a new array

    that append trick is very cool, exactly what i was looking for. Thanks!