Ask AI
Skip to main content

Set an item in a list

Function: Set an item in a list

This action helps you manage your lists of information by either adding a new item to the end of a list or updating an existing item at a specific position within the list. It's useful for keeping collections of data organized and up-to-date.

Input

  • List
    • Description: The collection of items (like a shopping cart, a to-do list, or a list of customer names) that you want to modify.
    • Type: List of any type of item.
  • Item
    • Description: The specific value or piece of data you want to add to the list or use to replace an existing item. This input is required.
    • Type: Any type of item (text, number, date, etc.).
  • Index
    • Description: The position in the list where you want to place the 'Item'.
      • If you leave this empty, the 'Item' will be added to the very end of the list.
      • If you provide a number (e.g., 0 for the first item, 1 for the second, and so on), the item currently at that position will be replaced with your new 'Item'.
    • Type: Whole Number.

Output

This action does not produce a new output. Instead, it directly modifies the 'List' you provided as an input. The changes are applied to the original list.

Execution Flow

Real-Life Examples

Here are some practical ways you can use the "Set an item in a list" action:

Example 1: Adding a new product to a shopping cart

Imagine you have a list representing a customer's shopping cart, and you want to add a new product.

  • Inputs:
    • List: ["Laptop", "Mouse"] (Current items in the cart)
    • Item: "Keyboard" (The new product to add)
    • Index: (Leave empty)
  • Result: The shopping cart list will be updated to ["Laptop", "Mouse", "Keyboard"].

Example 2: Updating a task in a project to-do list

You have a list of project tasks, and one task needs to be updated with a more specific description.

  • Inputs:
    • List: ["Plan meeting", "Draft report", "Send emails"] (Your current tasks)
    • Item: "Finalize project report" (The updated task description)
    • Index: 1 (Assuming "Draft report" is at position 1, as lists often start counting from 0)
  • Result: The project to-do list will be updated to ["Plan meeting", "Finalize project report", "Send emails"].

Example 3: Starting a new list of favorite movies

You want to create a list of your favorite movies, starting with the first one.

  • Inputs:
    • List: [] (An empty list, as you're just starting)
    • Item: "The Matrix" (Your first favorite movie)
    • Index: (Leave empty)
  • Result: The favorite movies list will now contain ["The Matrix"].