List.copy
copy($options={}) -> list
Description
Copy the List into a new List.
Any items that are Lists or Maps will also be copied, recursively.
$list1 = [1, 2, 3] $list2 = $list1.copy() $list1[1] = 11 $list2[1] = 22 print($list1) //= [11, 2, 3] print($list2) //= [22, 2, 3]
Options
Option | Value | Description |
---|---|---|
refs |
true/false | All child List or Map objects will use references instead of duplicated copies. This is more memory efficient, but can result in hard-to-find bugs. We recommend only using this for very large data structures. |
$list1 = [ { num: 111 } { num: 222 } ] $list2 = $list1.copy(-refs) // This will ALSO change the value in the original list $list2[1].num = 999 $list1[1].num //= 999