Powered By GitBook
BUILD_OBJECT
Build an object from a list of key-value objects

Description

Given a list of objects and the names of two properties that the objects in the list have, constructs a dictionary object.
The algorithm runs as follows: start with an empty result object. For every object in the source list, pick the value of the Key value property, and assign it to the result object under a property whose name is the value of Key name property.
If multiple objects in the list have the same value for their Key name property, the dictionary will have the value of the Value name property of the last object in the list.

Function signature

1
BUILD_OBJECT(list: Array, keyname: String, valuename: String) => Object
Copied!
Parameter
Description
List
The list of objects from which the object will be built
Key name
Property name in the source list object whose value to use as dictionary object key
Value name
Property name in the source list object whose value to use as dictionary object value

Examples

1
array = [{"id":"abc","label":"ABC label"},{"id":"def","label":"DEF label"}]
2
animals = [
3
{
4
"name": "cat",
5
"age": 2,
6
"height": 0.4
7
},
8
{
9
"name": "dog",
10
"age": 3,
11
"height": 0.6
12
},
13
{
14
"name": "mouse",
15
"age": 1,
16
"height": 0.1
17
}
18
]
Copied!
Formula
Return value
BUILD_OBJECT(array, "id", "label")
{"abc":"ABC label","def":"DEF label"}
BUILD_OBJECT(animals, "name", "age")
{"cat":2,"dog":3,"mouse":1}
BUILD_OBJECT(animals, "name", "height")
{"cat":0.4,"dog":0.6,"mouse":0.1}
Last modified 11mo ago
Export as PDF
Copy link