Skip to main content

objectEntries

objectEntries ( object : object ) : collection

ParameterTypeDescription
objectobject->Object to return contents
Resultcollection<-Collection of objects with key / value properties

Description

The objectEntries 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
var result1, result2 : string

persons = newObject
persons["John"] = 42
persons["Andy"] = 24
persons["Mary"] = 30
persons["Paul"] = 50

result1 = "The average age is "+string(objectValues(persons).average())
result1 = result1+"/rThere are "+string(objectKeys(persons).length)+" persons"

ages = objectEntries(persons).query("value>:1",25)
result2 = "There are "+string(ages.length)+" persons who are over 25"
result2 = result2+"/rTheir names are: "+ages.extract("key").join("-")

See also

objectKeys
objectValues