Skip to main content

%Library.DynamicArray

class %Library.DynamicArray extends %Library.DynamicAbstractObject

Dynamic Array type class

Method Inventory

Methods

method %Get(key) as %CacheString
Given the index position of a value in an array, return the actual value that corresponds to the index If the value does not exist, a null string "" is returned. You can differentiate between an unassigned value that returns a "" string and a real "" string using %GetTypeOf().

key The index position of the value you wish to retrieve, indexes begin at position 0. This must be passed as a canonical integer value.

Returns The value of the data as defined by index position 'key'. If the value does not exist, a null string "" is returned. You can differentiate between an unassigned value that returns a "" string and a real "" string using %GetTypeOf()

method %GetIterator() as %Iterator.Array
Inherited description:

Perform an iteration of all the values in a %DynamicAbstractObject subclass.

In the example below, we will output all values contained in a %DynamicObject.

     set iter = obj.%GetIterator()
     while iter.%GetNext(.key , .value ) {
        write "key = "_key_" , value = "_value,!
     }
  
method %IsDefined(key) as %Boolean
Tests if a key is defined within an array

key The index position of the value you wish to test, indexes begin at position 0. This must be passed as a canonical integer value.

Returns A boolean value to show if a value is defined (1) or not (0).

method %Pop() as %CacheString
Returns the value of the last member of the array. The value is then removed from the array. Nothing is removed if the array is empty.

Note: Any of the 4 situations causes %Pop() to return the empty string, "":

  • (1) Popping from an empty array
  • (2) Last member is the empty string
  • (3) Last member is the value null
  • (4) Last member is unassigned

If you want to differentiate between these 4 cases then you must test the array and its last element before calling the %Pop method.

Returns The value of the last member of the array.
If the array is empty, the method returns the empty string, "".

method %Push(value, type) as %DynamicAbstractObject

Given a new value, append it to the end of the current array, increasing the length of the array.

value The new value to push.

type OPTIONAL, the type of the value to push.

If the type argument is present then it must be one of the following strings:
"null" - JSON null, must be ""
"boolean" - Either 0 or nonzero integer
"number" - Convert to numeric value
"string" - Convert to text string

Returns An oref referencing the current modified array, allowing calls to %Push() to be chained.

method %Remove(pos) as %DynamicAbstractObject
Remove the element at the specified index position from the %DynamicArray. If the value of the %DynamicArray element is an embedded %DynamicArray or %DynamicObject, delete all subordinate nodes as well. All %DynamicArray elements following the removed element will have their subscript position decremented by 1.

pos Index position within the %DynamicArray of the element you wish to remove

Returns The value of the removed %DynamicArray element.

method %Set(key, value, type) as %DynamicAbstractObject
Create a new value or update an existing value.

key The index position of the value you wish to create , indexes begin at position 0. This must be passed as a canonical integer value.

value The new value with which to update the previous value or create a new value.

type OPTIONAL, the type of the value being assigned.

If the type argument is present then it must be one of the following strings:
"null" - JSON null, must be ""
"boolean" - Either 0 or nonzero integer
"number" - Convert to numeric value
"string" - Convert to text string

Returns An object to the current modified array, allowing calls to $set() to be nested.

Inherited Members

Inherited Methods

FeedbackOpens in a new tab