assistance-engine/docs/developer.avapframework.com/appendices_11.md

1.5 KiB

itemFromList()

The itemFromList() command extracts a specific element from a list based on a given index and stores the result in a target variable. This is useful for accessing individual elements within a list.

Parameters

  • SourceVariable Type: var Description: The variable containing the list from which an element is to be extracted. It can be a variable that stores the list or a direct value representing the list.
  • index Type: value Description: The index of the element to be extracted from the list. It must be an integer value that indicates the position of the element within the list.
  • TargetVariable Type: var Description: The variable where the extracted element will be stored. It must be a variable that will receive the value of the element at the specified index position.

Command Flow

Usage Example

Suppose the list in myList is ['apple', 'banana', 'cherry'] and you want to extract the element at index 1.

// Variable definitions
myList = ['apple', 'banana', 'cherry']
element = ''

// Call the command to extract the element at index 1
itemFromList(myList, 1, element)

// Return the extracted element through addResult
addResult(element)

Since index 1 corresponds to the element 'banana' in the myList, the itemFromList() command will extract 'banana' and store it in the variable element. The element variable will be returned through addResult(element), resulting in the following output:

"banana"