Get a sublist
Function: Get a sublist
This function allows you to create a new list by selecting a specific portion (a "sublist") from an existing list. You define where the new list should begin and end using numerical positions (indices). This is useful for processing only a part of a larger collection of items.
Input
- List: The original list of items from which you want to extract a sublist.
- Type: Array of Variables
- Start index: The numerical position where the new sublist should begin. The first item in a list is at position 0.
- Type: Number (Required)
- End index: The numerical position where the new sublist should end. The item at this position is not included in the new sublist.
- Type: Number (Required)
Output
- Result: The name of the variable where the newly created sublist will be stored. This variable will contain an array of the selected items.
- Type: Array of Variables (Required, Default: "LIST")
Execution Flow
Real-Life Examples
Example 1: Extracting a Middle Section of a Product List
Imagine you have a list of products and you want to display only the products from the 3rd to the 5th position (inclusive) on a specific page.
- Inputs:
- List:
["Laptop", "Mouse", "Keyboard", "Monitor", "Webcam", "Headphones", "Microphone"] - Start index:
2(to start from "Keyboard", which is at index 2) - End index:
5(to end before "Headphones", which is at index 5, thus including "Keyboard", "Monitor", "Webcam") - Result:
FeaturedProducts
- List:
- Result: A new list named
FeaturedProductswill be created containing["Keyboard", "Monitor", "Webcam"].
Example 2: Getting the First Few Items from a To-Do List
You have a long to-do list and only want to show the first three tasks on your dashboard.
- Inputs:
- List:
["Buy groceries", "Call plumber", "Schedule meeting", "Draft report", "Reply to emails", "Plan vacation"] - Start index:
0(to start from the very beginning) - End index:
3(to include items at index 0, 1, and 2) - Result:
TopTasks
- List:
- Result: A new list named
TopTaskswill be created containing["Buy groceries", "Call plumber", "Schedule meeting"].
Example 3: Handling Out-of-Bounds Indices for a User List
You have a list of users and you want to get a sublist, but you accidentally provide a negative start index and an end index that's too large. The platform will gracefully adjust these values.
- Inputs:
- List:
["Alice", "Bob", "Charlie", "David", "Eve"] - Start index:
-1(The platform will treat this as0) - End index:
10(The platform will treat this as the list's actual size,5) - Result:
ActiveUsers
- List:
- Result: A new list named
ActiveUserswill be created containing["Alice", "Bob", "Charlie", "David", "Eve"], effectively returning the entire list because the adjusted start was 0 and the adjusted end was 5.