This example creates a sparse array. The array is zero-based and has six elements, but only elements 0, 1, and 5 have an assigned value. The null elements displayed in the JSON string are just placeholders for the unassigned values:
set dynArray=["abc",999]
set dynArray."5" = "final"
write dynArray.%Size()_" elements: "_dynArray.%ToJSON()
6 elements: ["abc",999,null,null,null,"final"]
%GetNext() will return only the three elements with values, skipping all unassigned elements:
set iterator=dynArray.%GetIterator()
while iterator.%GetNext(.key,.val) { write !, "Element index: "_key_", value: "_val }
Element index: 0, value: abc
Element index: 1, value: 999
Element index: 5, value: final
See the next section (“Understanding Sparse Arrays and Unassigned Values”) for more on sparse arrays.