Skip to main content
Version: Next

OB Entries

OB Entries ( object ) : Collection

ParameterTypeDescription
objectObjectObject to return contents
Function resultCollectionCollection of objects with key / value properties

This command is not thread-safe, it cannot be used in preemptive code.

Description

The OB Entries command returns a collection of objects containing the contents of the object as key / value property pairs.

Each returned object contains the following properties:

PropertyTypeDescription
keystringenumerable property name of the object
valuevariantenumerable property value of the object

Only first-level property names are returned (property names of sub-objects are not returned). The order of properties within the returned collection follows the definition order of the properties.

Example

Using an object as an hash map (key / value system) provides a quick and direct access to data, just like when using an index (e.g., if we need Mary's age, we can write: $persons["Mary"])

 var $individual;$persons : Object
 var $names;$ages : Collection
 
 $persons:=New object
 $persons["John"]:=42
 $persons["Andy"]:=24
 $persons["Mary"]:=30
 $persons["Paul"]:=50
 
 ALERT("The average age is "+String(OB Values($persons).average()))
 ALERT("There are "+String(OB Keys($persons).length)+" persons")
 
 $ages:=OB Entries($persons).query("value>:1";25)
 ALERT("There are "+String($ages.length)+" persons who are over 25")
 
 ALERT("Their names are: "+$ages.extract("key").join("-"))

See also

OB Keys
OB Values