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.
, the operators access the parent struct and child arrays in the following order:
The dot operator accesses the array
drinks
.
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