Object features

DefineDefault()

Instead showing an error, define a default value for object, map and array to return when the key / Item / property does not exist.

ObjMapArray := ObjMapArray.DefineDefault([Value])
Command  Example: ObjMapArray.DefineDefault ""
Function Example: ObjMapArray.DefineDefault("")
OutputVar

The name of the variable to store the object, array or map.

Value

The default value (number, string, object, ...) to return when a key / Item / property does not exist.
Leave that parameter empty to restore default behaviour (show an error).

Remarks

DefaultValue can also be defined globally using #DefineDefaultObjectValue / #DefineDefaultArrayValue / #DefineDefaultMapValue.

Examples

obj:=[].DefineDefault("Item does not exist!")
MsgBox obj[1] ; Item does not exist!
obj.DefineDefault ''
MsgBox obj[2] ; empty
obj.DefineDefault ; restore
MsgBox obj[1] ; Error: invalid Index.

__Item for Objects

Objects can read and write properties using . and [] syntax.

Remarks

Key for properties is always a string. When number is given, it will be converted to string.

Examples

obj:={}
obj.1:="test"
obj[2]:="more"
MsgBox obj.2

UMap() / UArray() / UObject()

Create unsorted Map (applies to items and properties) / Array or Object (applies to properties only).
Normally Integers, Objects and Strings are saved separately and sorted alphabetically for performance. Using UMap/UArray/UObject items and properties will be saved and enumerated in the same order they were added.

Examples

map:=UMap("z",1,"a",2,%'99'%,3,%'1'%,4)
for k, v in map
  MsgBox k "=" v

MapFromObject

Map() accepts 1 object parameter and uses it for initialization, the object can be either Object, Map or Array.

Examples

obj:=Map({z:1,a:2,99:3,1:4})
for k, v in obj
  MsgBox k "=" v