Build an array containing a nested array. The final call to %Push() specifies the optional type argument to store a boolean value as JSON false rather than ObjectScript 0 (see “Overriding a Default Datatype with %Set() or %Push()”):
set array=[]
do array.%Push(42).%Push("abc").%Push([])
do array."2".%Push("X").%Push(0,"boolean")
write array.%ToJSON()
[42,"abc",["X",false]]
Remove all elements of the nested array. Like all dynamic entity methods, %Pop() will return ObjectScript 0 rather than JSON false:
for i=0:1:1 {write "/"_array."2".%Pop()_"/ "}
/0/ /X/
write array.%ToJSON()
[42,"abc",[]]
Now remove all elements of the main array, including the empty nested array:
for i=0:1:2 {write "/"_array.%Pop()_"/ "}
/2@%Library.DynamicArray/ /abc/ /42/
write array.%ToJSON()
[]
These examples use hard coded for loops for simplicity. See “Sparse Array Iteration with %Size()” for more realistic examples of array iteration.