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

Struct with array elements

Struct with array elements

To access elements in an array within a struct, use a dot operator followed by a subscript operator. The dot operator first accesses the specified array in the struct. Then, the subscript operator accesses an element in the array based on the index value.

Example

You have the following struct with arrays
drinks
,
sandwiches
, and
salads
:
menu_struct{ drinks: ['milk','coffee','tea','chai'] sandwiches: ['ham','turkey',NULL] salads: ['caesar','cobb','greek','chipotle'] }
If you use the expression
menu_struct.drinks[0]
, the operators access the parent struct and child arrays in the following order:
  1. The dot operator accesses the array
    drinks
    .
  2. The subscript operator accesses the value at position 0 in the array
    drinks: ['milk','coffee','tea','chai']
    and returns
    'milk'
    .
The following expressions show more examples that use a dot operator followed by a subscript operator to access values in the child arrays in the parent struct
menu_struct
:
Input Value
RETURN VALUE
menu_struct.drinks[1]
'coffee'
menu_struct.sandwiches[2]
NULL
menu_struct.salads[3]
'chipotle'
menu_struct.drinks[0,3]
['milk','coffee','tea']

0 COMMENTS

We’d like to hear from you!