Iterable Operators
Iterable operators allow you to work with collections of data such as lists and arrays. These operators help you access, filter, and manipulate elements within your data structures.
Available Operators
contains()
Checks if a collection contains a specific element.
Syntax:
${contains(collection, element)}Parameters:
collection- The list or array to search inelement- The value to search for
Returns: true if the element exists in the collection, false otherwise
Examples:
// Check if a list contains a value
${contains(["apple", "banana", "orange"], "banana")}
// Returns: true
${contains([1, 2, 3, 4, 5], 6)}
// Returns: false
// Check if user's tags include "premium"
${contains(user.tags, "premium")}
// Conditional based on contains
${if(contains(selectedItems, currentItem.id), "Selected", "Not Selected")}Use Cases:
Verify if an item is in a selection
Check if a user has a specific permission or tag
Validate if a value exists before processing
Implement toggle functionality (add/remove from list)
elementAt()
Returns the element at a specific index in a collection.
Syntax:
Parameters:
collection- The list or arrayindex- Zero-based index position (0 for first element, 1 for second, etc.)
Returns: The element at the specified index, or null if index is out of bounds
Examples:
Use Cases:
Access specific items by position
Get items based on calculated indices
Retrieve elements when index comes from user input or state
Alternative to bracket notation
myList[index]
firstElement()
Returns the first element of a collection.
Syntax:
Parameters:
collection- The list or array
Returns: The first element, or null if the collection is empty
Examples:
Use Cases:
Show the most recent item (if list is sorted by date)
Get the top result from search or filter
Display featured or highlighted item
Quick access to first element without indexing
lastElement()
Returns the last element of a collection.
Syntax:
Parameters:
collection- The list or array
Returns: The last element, or null if the collection is empty
Examples:
Use Cases:
Show the most recent item (if appending to end)
Display the final element without calculating index
Access last page in pagination
Get the latest entry in chronological data
skip()
Returns a new collection that skips the first N elements.
Syntax:
Parameters:
collection- The list or arraycount- Number of elements to skip from the beginning
Returns: A new collection with the first count elements removed
Examples:
Use Cases:
Implement pagination (skip previous pages)
Remove header rows from data
Start displaying from a certain position
Offset-based data loading
take()
Returns a new collection containing only the first N elements.
Syntax:
Parameters:
collection- The list or arraycount- Number of elements to take from the beginning
Returns: A new collection with only the first count elements
Examples:
Use Cases:
Limit number of displayed items
Show "top N" results
Preview or teaser lists (e.g., "Top 5 Products")
Implement "Show More" functionality
reversed()
Returns a new collection with elements in reverse order.
Syntax:
Parameters:
collection- The list or array to reverse
Returns: A new collection with elements in opposite order
Examples:
Use Cases:
Show newest items first (reverse chronological order)
Display data in descending order
Create countdown or reverse sequences
Reverse user selections
Combining Operators
You can chain multiple iterable operators together for powerful data manipulation:
Pagination Example
Limited Reversed List
Skip and Check
Conditional Access
Common Patterns
Empty List Handling
Show Limited Preview
Pagination Controls
Checking Selection State
Accessing Specific Elements
Best Practices
Check length before accessing: Always verify the collection has elements before using
firstElement(),lastElement(), orelementAt()Use appropriate operators: Choose
firstElement()overelementAt(myList, 0)for clarityCombine for pagination: Use
skip()andtake()together for efficient paginationCache results: If using the same operation multiple times, consider storing the result in a variable
Handle null cases: Use
or()or conditionalif()to provide fallbacks when elements might not existMind performance: While operations are efficient, avoid deeply nested chains in large lists displayed in UI
Related Documentation
List Variable - Working with list data
JSON Operators - Working with JSON objects
Logical Operators - Conditional logic
Math Operators - Mathematical operations for indices and counts
ListView - Displaying lists in UI
GridView - Displaying grids in UI
Last updated