Table of Contents

Search

  1. Preface
  2. Function reference
  3. Constants
  4. Operators
  5. Dates
  6. Functions
  7. System variables
  8. Datatype reference

Function Reference

Function Reference

Array of structs

Array of structs

An array of structs is an array with struct elements. Use a combination of subscript and dot operators to access a child struct and the elements in the child struct.
To access an element in a child struct within a parent array, use a subscript operator followed by a dot operator. You can also reverse the order of the operators without changing the return value.

Examples

You have the following array of structs
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 } ]
You can access an element in one of the child structs using complex operators in either of the following orders:
You use a subscript operator and then a dot operator.
The operators access the array of structs in the following order:
  1. The subscript operator accesses the indexed element in the array and returns a struct.
  2. The dot operator accesses an element in the struct.
For example, the following expressions use a subscript operator followed by a dot operator to access elements in 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
You use a dot operator and then a subscript operator.
The operators access the array of structs in the following order:
  1. The dot operator locates elements with the same name from each of the structs and returns an array.
  2. The subscript operator accesses the indexed element in the array.
For example, the following expressions show the return value when you use a dot operator to access elements in the array
employee_info_array
:
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]
The following expressions show the return value when you use a dot operator followed by a subscript operator to access elements in the array
employee_info_array
:
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!