Table of Contents

Search

  1. Preface
  2. The Transformation Language
  3. Constants
  4. Operators
  5. Variables
  6. Dates
  7. Functions

Transformation Language Reference

Transformation Language Reference

Array with Struct Elements

Array with Struct Elements

An array with struct elements is an array of structs. Use a combination of subscript and dot operators to access an element in a struct that is within an array.
To access an element in a struct within an array, use a subscript operator followed by a dot operator. You can also reverse the order of the operators. Return values are the same regardless of the order of the operators. Based on the order of the complex operators, the element is accessed as follows:
You use a subscript operator followed by a dot operator.
The subscript operator first accesses the indexed element in the array and returns a struct. Then, the dot operator accesses an element within the struct.
You use a dot operator followed by a subscript operator.
The dot operator locates elements with the same name from each of the structs and returns an array. Then, the subscript operator accesses an element within the array.
For example, you have the following array,
employee_info_array
:
employee_info_array = [ derrick_struct{ name: 'Derrick' city: NULL state: 'NY' }, kevin_struct{ name: 'Kevin' city: 'Redwood City' state: 'CA' }, lauren_struct{ name: 'Lauren' city: 'Woodcliff Lake' state: NULL } ]
The following expressions use a subscript operator followed by a dot operator on the array
employee_info_array
:
Input Value
RETURN VALUE
employee_info_array[0].name
'Derrick'
employee_info_array[1].city
'Redwood City'
employee_info_array[2].state
NULL
When you use a dot operator first, the dot operator returns an array with elements of the same name from each struct. For example, the following expressions show the return value when you use a dot operator:
Input Value
RETURN VALUE
employee_info_array.name
['Derrick','Kevin','Lauren']
employee_info_array.city
[NULL,'Redwood City','Woodcliff Lake']
employee_info_array.state
['NY','CA',NULL]
Then, the subscript operator accesses an element in the returned array. The following expressions use a dot operator followed by a subscript operator:
Input Value
RETURN VALUE
employee_info_array.name[0]
'Derrick'
employee_info_array.city[1]
'Redwood City'
employee_info_array.state[2]
NULL
Note that the return values are the same whether you use a subscript operator or a dot operator first. For example, the expressions
employee_info_array[0].name
and
employee_info_array.name[0]
have the same return value
'Derrick'
.

0 COMMENTS

We’d like to hear from you!