Click or drag to resize
Array data type
Print this page

The data type Array<> represents a typed and ordered list of items.

Usage

When working with an array in TDE, you have the option to work either with the full array or with individual items within the array by index. Array indices start at zero.

Note Note

When you create an array by index number, if you do not provide a value for each item within the array, then the missing items are set to null. Warning: It is up to each table to determine if nulls are allowed. See the table documentation for specific validation requirements.

The examples below demonstrate how to work with arrays in TDE templates. The examples use the ScheduleStart and ScheduleStop columns from the Condition table. Both columns are of the data type Array<TimeInterval> and contain TimeInterval values for each day of the week.

To update a full array, use the following syntax:

Update template
[Output]
ScheduleStop = Input.ScheduleStop

An input file for the template above should contain an array of TimeInterval values for ScheduleStop:

CSV
Name,ScheduleStop
Condition1,"00:00:00,20:30:00,21:00:00,21:30:00,22:00:00,22:30:00,00:00:00"

To update an array by index number, use the following syntax:

Update template
[Output]
ScheduleStart[0] = Input.ScheduleStartSunday
ScheduleStart[2] = Input.ScheduleStartTuesday

An input file for the template above should contain individual TimeInterval values for the first and third indices of the ScheduleStart array:

CSV
Name,ScheduleStartSunday,ScheduleStartTuesday
Condition1,05:00:00,00:00:00

To update a full array using individual input values, use the following syntax:

Update template
[Output]
ScheduleStart = [Input.Sunday,Input.Monday,Input.Tuesday,Input.Wednesday,Input.Thursday,Input.Friday,Input.Saturday]

An input file for the template above should contain a TimeInterval value for each item in the ScheduleStart array:

CSV
Name,Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday
Condition1,00:00:00,05:00:00,05:00:00,09:00:00,09:00:00,05:00:00,00:00:00
Note Note

When you create or update an array using individual input values as shown above, and one of those items matches an IgnoreValue that you have defined in your [Template] section, then that item's value is converted to null.

To retrieve a full array, use the following syntax:

Retrieve template
[Output]
ScheduleStart = Input.ScheduleStart

In the example XML response below, the full ScheduleStart array is returned:

XML
<?xml version="1.0" encoding="utf-8"?>
<RetrieveStartingSchedules>
    <TableEntry ScheduleStart="01:30:00,02:30:00,03:00:00,04:30:00,05:00:00,06:30:00,07:00:00" />
    <TableEntry ScheduleStart="09:00:00,09:00:00,09:00:00,09:00:00,09:00:00,09:00:00,09:00:00" />
</RetrieveStartingSchedules>

To retrieve a specific item within an array, specify the item’s index number within the array:

Retrieve template
[Output]
ScheduleStartSunday = Input.ScheduleStart[0]

In the example JSON response below, only the first item within the ScheduleStart array is returned:

JSON
{
  "RetrieveStartingSchedules": {
    "TableEntry": [
      {
        "ScheduleStartSunday": "01:30:00"
      },
      {
        "ScheduleStartSunday": "09:00:00"
      }
    ]
  }
}
JavaScript conversion

When you use the optional [Script] section to insert your own JavaScript functions, Array<> maps to JavaScript Array, with JavaScript native array assignment.

Caution note Caution

Currently, Array<> JavaScript conversion is only supported within Retrieve templates.

Creation
JavaScript
var myArray = [x,y,z];
var myEmptyArray = [];
Methods

These are the native JavaScript methods for Array objects:

  • concat() — Joins two or more arrays, and returns a copy of the joined arrays

  • indexOf() — Search the array for an element and returns its position

  • join() — Joins all elements of an array into a string

  • lastIndexOf() — Search the array for an element, starting at the end, and returns its position

  • pop() — Removes the last element of an array, and returns that element

  • push() — Adds new elements to the end of an array, and returns the new length

  • reverse() — Reverses the order of the elements in an array

  • shift() — Removes the first element of an array, and returns that element

  • slice() — Selects a part of an array, and returns the new array

  • sort() — Sorts the elements of an array

  • splice() — Adds/Removes elements from an array

  • toString() — Converts an array to a string, and returns the result

  • unshift() — Adds new elements to the beginning of an array, and returns the new length

  • valueOf() — Returns the primitive value of an array