A quick array copy can be achieved by appending to a new array:
array1 = [
"value1"
"value2"
"value3"
]
array2 = []
array2.Append(array1)
This will still have the issue of copying references to the inner objects to the new array, but it's a quicker way to break the top-level reference if using base types.
For deeper references, I use the following function which will copy all elements of an array or associative array down to the specified depth. A depth of 0, the default, does basically the same as the Append method above:
Function ShallowCopy(array As Dynamic, depth = 0 As Integer) As Dynamic
If Type(array) = "roArray" Then
copy = []
For Each item In array
childCopy = ShallowCopy(item, depth)
If childCopy <> invalid Then
copy.Push(childCopy)
End If
Next
Return copy
Else If Type(array) = "roAssociativeArray" Then
copy = {}
For Each key In array
If depth > 0 Then
copy[key] = ShallowCopy(array[key], depth - 1)
Else
copy[key] = array[key]
End If
Next
Return copy
Else
Return array
End If
Return invalid
End Function
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)