Ask AI
Skip to main content

Add value to an object

Function: Add value to an object

This function allows you to add a specific piece of information (a "value") to an existing collection of data (an "object"). You identify where to place this new information within the object using a unique label (a "key"). If the key already exists, its current value will be updated with the new one. If the key doesn't exist, a new entry will be created.

Input

  • Object: The collection of data you want to modify. This is where you'll add or update information.
  • Key: A unique label (like a name or identifier) that tells the system exactly where to put the new value within your object. This must be text.
  • Value (Optional): The actual information you want to store. This can be text, a number, a date, a true/false statement, or any other type of data. If you leave this empty, the key will be added to the object with no specific value assigned (or its existing value will be cleared).

Output

This function does not produce a separate output. Instead, it directly modifies the "Object" you provided as an input. The changes are applied to that object.

Execution Flow

Real-Life Examples

Here are some examples of how you can use the "Add value to an object" function:

Example 1: Adding a new contact detail to a customer record

Imagine you have a customer's contact information stored as an object, and you want to add their new mobile number.

  • Inputs:
    • Object: \{"Name": "Alice Smith", "Email": "[email protected]"\}
    • Key: "Mobile"
    • Value: "555-123-4567"
  • Result: The customer object is updated to include the new mobile number: \{"Name": "Alice Smith", "Email": "[email protected]", "Mobile": "555-123-4567"\}

Example 2: Updating a product's stock quantity

You have an object representing a product in your inventory, and its stock level needs to be updated after a sale.

  • Inputs:
    • Object: \{"ProductID": "P101", "Name": "Laptop Pro", "Stock": 50, "Price": 1200\}
    • Key: "Stock"
    • Value: 49
  • Result: The product object's stock quantity is updated: \{"ProductID": "P101", "Name": "Laptop Pro", "Stock": 49, "Price": 1200\}

Example 3: Marking a task as completed

You have a task object and want to mark it as finished, also noting the completion date.

  • Inputs:
    • Object: \{"TaskID": "T005", "Description": "Prepare Q3 Report", "Status": "In Progress"\}
    • Key: "Status"
    • Value: "Completed"
  • Result: The task object now shows the updated status: \{"TaskID": "T005", "Description": "Prepare Q3 Report", "Status": "Completed"\}