Skip to main content
Cargo uses JavaScript expressions to manipulate data within workflows. This cheat sheet covers the most commonly used methods for working with strings, arrays, and data transformations.
All expressions must be wrapped in double curly brackets: {{ expression }}

Quick reference


String methods

Split a string by a delimiter to extract specific parts.Example: Extract domain from email address
Inputnodes.start.email = "[email protected]"
Output"acme-corp.com"
{{ nodes.start.email.split("@")[1] }}
Convert a string to lowercase for consistent formatting.Example: Standardize company name
Inputnodes.start.companyName = "ACME Corporation"
Output"acme corporation"
{{ nodes.start.companyName.toLowerCase() }}
Convert a string to uppercase.Example: Format country code
Inputnodes.start.country = "us"
Output"US"
{{ nodes.start.country.toUpperCase() }}
Remove whitespace from both ends of a string.Example: Clean user input
Inputnodes.start.name = " John Smith "
Output"John Smith"
{{ nodes.start.name.trim() }}
Replace part of a string with another value.Example: Anonymize email domain
Inputnodes.start.email = "[email protected]"
Output"john@[redacted].com"
{{ nodes.start.email.replace("competitor", "[redacted]") }}
Use replaceAll() to replace all occurrences, not just the first one.

Array methods

Count how many items are present in an array.Example: Count the number of stakeholders found
Inputnodes.array = ["John Smith", "Sarah Johnson", "Mike Davis", "Lisa Chen"]
Output4
{{ nodes.array.length }}
Check if a value exists in an array.Example: Check if the product is in an allowed list
Inputnodes.start.product = "posters"
Allowed["posters", "calendars", "books", "cards"]
Outputtrue
{{ ["posters", "calendars", "books", "cards"].includes(nodes.start.product) }}
Extract a portion of an array.Example: Limit stakeholders to first 5
Inputnodes.apollo.stakeholders = ["John", "Sarah", "Mike", "Lisa", "David", "Emma", "Tom"]
Output["John", "Sarah", "Mike", "Lisa", "David"]
{{ nodes.apollo.stakeholders.slice(0, 5) }}
slice(start, end) extracts elements from index start up to (but not including) end.
Create a new array based on a condition.Example: Filter case study URLs
Input["https://example.com/case-studies/tech", "https://example.com/blog", "https://example.com/case-studies/finance"]
Output["https://example.com/case-studies/tech", "https://example.com/case-studies/finance"]
{{ nodes.start.urls.filter((url) => url.includes("/case-studies/")) }}
Convert an array to a string with a delimiter.Example: Convert countries to comma-separated string
Inputnodes.start.countries = ["US", "CA", "UK", "DE"]
Output"US, CA, UK, DE"
{{ nodes.start.countries.join(", ") }}
Transform each element in an array.Example: Add company data to stakeholders
// nodes.apollo.stakeholders
[
  { "name": "John", "title": "CEO" },
  { "name": "Sarah", "title": "CTO" }
]

// nodes.start.domain = "acme.com"
// nodes.hubspot.companyId = "12345"

{{
  nodes.apollo.stakeholders.map((stakeholder) => ({
    ...stakeholder,
    domain: nodes.start.domain,
    hubspotId: nodes.hubspot.companyId,
  }))
}}
Return the first element that matches a condition.Example: Find the CEO in a stakeholders list
Input[{ "name": "John", "title": "CEO" }, { "name": "Sarah", "title": "CTO" }]
Output{ "name": "John", "title": "CEO" }
{{ nodes.apollo.stakeholders.find((s) => s.title === "CEO") }}
Returns undefined if no element matches. Use optional chaining (?.) to safely access properties.
Merge two arrays together.Example: Combine prospect lists
Inputnodes.start.countries1 = ["US", "CA"] and nodes.start.countries2 = ["UK", "DE"]
Output["US", "CA", "UK", "DE"]
{{ nodes.start.countries1.concat(nodes.start.countries2) }}

Date and time

Create a timestamp.Example: Get current timestamp
Output"2024-01-15T10:30:45.123Z"
{{ new Date() }}
Format date in localized format.Example: Format current date
Output"1/15/2024"
{{ new Date().toLocaleDateString() }}
Pass a locale string for different formats: toLocaleDateString('en-GB') returns "15/01/2024"

Mathematical operations

Perform calculations on numbers.Example: Calculate win rate
Inputnodes.start.wins = 15, nodes.start.total = 50
Output30
// Add to balance
{{ nodes.start.balance + 100 }}

// Calculate percentage
{{ (nodes.start.wins / nodes.start.total) * 100 }}
Other common operations:
// Round to 2 decimal places
{{ Math.round(nodes.start.value * 100) / 100 }}

// Get the maximum value
{{ Math.max(nodes.start.a, nodes.start.b) }}

// Get the minimum value
{{ Math.min(nodes.start.a, nodes.start.b) }}

Common patterns

Use ternary operators for simple conditions.Example: Set priority based on score
Inputnodes.start.score = 85
Output"High Priority"
{{ nodes.start.score > 80 ? "High Priority" : "Standard" }}
Nested conditions:
{{ nodes.start.score > 80 ? "High" : nodes.start.score > 50 ? "Medium" : "Low" }}
Access nested properties using dot notation.Example: Extract the city from a nested address
// nodes.start
{
  "user": {
    "address": {
      "city": "San Francisco"
    }
  }
}
{{ nodes.start.user.address.city }}
Safely access properties that might not exist using optional chaining.Example: Get theme with default fallback
// nodes.start
{
  "user": {
    "preferences": null
  }
}
// Safely access optional property
{{ nodes.start.user?.preferences?.theme }}

// With default fallback
{{ nodes.start.user?.preferences?.theme ?? "default" }}
Without ?., accessing preferences.theme when preferences is null would throw an error.
Provide fallback values when data might be missing.Example: Use a default name when none is provided
Inputnodes.start.name = undefined
Output"Anonymous"
// Using nullish coalescing
{{ nodes.start.name ?? "Anonymous" }}

// Using logical OR (also catches empty strings)
{{ nodes.start.name || "Anonymous" }}

Tips & best practices

  • Use autocomplete — Access the autocomplete feature while writing expressions by pressing / on your keyboard.
  • Node connections matter — You cannot use a node’s outputs in an expression when the node isn’t connected to prior nodes in the execution logic.
  • Zero-indexed arrays — Arrays in JavaScript are zero-indexed. The first element is at index 0, not 1.
  • Chain methods — You can chain multiple methods together: {{ nodes.start.email.split('@')[1].toLowerCase() }}