Clone method: Array class
Syntax
Clone()
Description
The Clone method returns a reference to a new array, which is a copy of the given array. It copies all levels of the array, meaning, if the array contains elements which are themselves arrays (actually references to arrays), then the copy contains references to copies of the subarrays. Furthermore, if the array contains elements that are references to the same subarray, then the copy contains references to different subarrays (which of course have the same value).
Parameters
None. The array object that the clone method is executed against is the array to be cloned. Assigning the result of this method assigns a reference to the new array.
Returns
An array object copied from the original.
Example
In the following example, &AAN2 contains the three elements like &AAN, but they are distinct arrays. The last line changes only &AAN2[1][1], not &AAN[1][1].
Local Array of Array of String &AAN, &AAN2;
&AAN = CreateArray(CreateArray("A", "B"), CreateArray("C", "D"), "E");
&AAN2 = &AAN.Clone();
&AAN2[1][1] = "Z";
After the following example, &AAN contains three elements: two references to the subarray that was &AAN[2] (with elements C and D), and a reference to a subarray with element E.
&AAN[1] = &AAN[2];
After the following example, &AAN2 contains three elements: references to two different subarrays both with elements C and D, and a subarray with element E.
&AAN2 = &AAN.Clone();
Related Topics