Get a sublist
Function: Get a sublist
This action allows you to extract a specific portion of an existing list and create a brand new list from it. You define where the new list should begin and end within the original list using numerical positions (indices). This is useful for breaking down large lists into smaller, more manageable segments.
Input
- List (ARRAY): The original list of items you want to work with. This is the source from which you'll extract a sublist.
- Start index (NUMBER): The position in the original list where your new sublist should begin. Remember that the first item in a list is at position 0, the second at position 1, and so on. This input is required.
- End index (NUMBER): The position in the original list where your new sublist should stop. The item at this 'End index' position itself will not be included in your new list. For example, if you want items from index 0 up to (and including) index 2, you would set 'End index' to 3. This input is required.
Output
- Result (ARRAY): The new list created from your selection. This new list will be stored in a variable with the name you provide here. If you don't specify a name, it will default to a variable named "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 second to the fourth position.
- Inputs:
- List:
["Laptop", "Mouse", "Keyboard", "Monitor", "Webcam", "Headphones"] - Start index:
1(to start from "Mouse") - End index:
4(to end before "Monitor", thus including "Mouse", "Keyboard", "Monitor") - Result:
FeaturedAccessories
- List:
- Result: A new list named
FeaturedAccessoriesis created, containing["Mouse", "Keyboard", "Monitor"].
Example 2: Getting the First Few Tasks from a To-Do List
You have a long list of tasks and you only want to focus on the first three tasks for today.
- Inputs:
- List:
["Review Report", "Schedule Meeting", "Update Project Plan", "Send Emails", "Prepare Presentation", "Follow-up Calls"] - Start index:
0(to start from the very beginning) - End index:
3(to end before the item at index 3, thus including items at 0, 1, 2) - Result:
TodayTasks
- List:
- Result: A new list named
TodayTasksis created, containing["Review Report", "Schedule Meeting", "Update Project Plan"].
Example 3: Isolating a Single Item from a List of Users
You need to get a specific user from a list, perhaps the third user, to perform an action on their profile.
- Inputs:
- List:
["Alice", "Bob", "Charlie", "David", "Eve"] - Start index:
2(to start at "Charlie") - End index:
3(to end before the item at index 3, thus only including "Charlie") - Result:
SelectedUser
- List:
- Result: A new list named
SelectedUseris created, containing["Charlie"].