The function KEYS takes an Object and returns a List containing all the keys from the key-value pairs associated with the Object.
This function takes a single Object as input. It returns a single List of strings: all of the keys from the key-value pairs associated with the given object. The order of key-value pairs in an object is not deterministic; as a result, neither is the order of the values in the resulting list.
Declaration
KEYS(object) -> list_of_values
Parameters
object (required, type: Object)
Any object.
Return Values
list_of_values (type: List)
A List containing all the keys from the key-value pairs in the input object. These keys will always be strings.
Note that the order of name-value pairs in an object is not deterministic; as a result, neither is the order of the keys in the resulting list.
Examples
Assume the following example has access to the following object:
example_object = {
"number": 1,
"string1": "hello",
"string2": "this is a string, John",
"internal_object": {
"first_name": "Jane",
"last_name": "Doe"
}
}
Note that values in the key-value pairs within example_object consists of myriad types of values. The the value associated with "number" is a Number (1), values associated with "string1" and "string2" are strings ("hello" and "this is a string, John", respectively), and the value associated with "internal_object" is a object ( {"first_name": "Jane", "last_name": "Doe"} ). This Object was chosen not because it is particularly likely to be encountered it in the wild, but to emphasize that the values within an object used as input for the KEYS function do not at all need to be same type as each other.
The following example takes example_object and outputs a List containing the keys from the key-value pairs that make up example_object. Note that while, in this example, the order of the items in the returned List matches the order of the keys given in the Object, this is not guaranteed to be the case. The order of key-value pairs in an object is not deterministic; as a result, neither is the order of the values in the resulting list:
KEYS(example_object) -> ["number", "string1", "string2", "internal_object"]
To obtain a List of the keys associated with an Object within an Object, the nested Object must be given directly to the function KEYS. This is what is done in the following example, where dot notation allows value associated with "internal_object" ( {"first_name": "Jane", "last_name": "Doe"} to be accessed as example_object.internal_object:
KEYS(example_object.internal_object) -> ["first_name", "last_name"]
Discussion
The KEYS function takes an object and returns a List containing all of the keys from the key-value pairs associated with the given object. To instead obtain List of the values, use the function VALUES.