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.

String methods

Split

Split a string by a delimiter to extract specific parts. Example: Extract domain from email address
  • Input: nodes.start.email = "john.smith@acme-corp.com"
  • Output: "acme-corp.com"
// Extract domain from email
{{ nodes.start.email.split('@')[1] }}

toLowerCase

Convert a string to lowercase for consistent formatting. Example: Standardize company name
  • Input: nodes.start.companyName = "ACME Corporation"
  • Output: "acme corporation"
// Standardize company name
{{ nodes.start.companyName.toLowerCase() }}

toUpperCase

Convert a string to uppercase. Example: Format country code
  • Input: nodes.start.country = "us"
  • Output: "US"
// Format country codes
{{ nodes.start.country.toUpperCase() }}

Array methods

length

Count how many items are present in an array Example: Count the number of stakeholders found
  • Input: nodes.array = ["John Smith", "Sarah Johnson", "Mike Davis", "Lisa Chen"]
  • Output: 4
// Count the number of items in the array
{{ nodes.array.length }}

includes

Check if a value exists in an array. Example: Check if the product is in an allowed list
  • Input: nodes.start.product = "posters"
  • Allowed products: ["posters", "calendars", "books", "cards"]
  • Output: true
// Check if product is in allowed list
{{ ['posters', 'calendars', 'books', 'cards'].includes(nodes.start.product) }}

slice

Extract a portion of an array. Example: Limit stakeholders to first 5
  • Input: nodes.apollo.stakeholders = "John", "Sarah", "Mike", "Lisa", "David", "Emma", "Tom"]
  • Output: ["John", "Sarah", "Mike", "Lisa", "David"]
// Get first 5 stakeholders from search results
{{ nodes.apollo.stakeholders.slice(0, 5) }}

filter

Create a new array based on a condition. Example: Filter case study URLs
  • Input: nodes.start.urls = ["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"]
// Keep only URLs containing case studies
{{ nodes.start.urls.filter(url => url.includes('/case-studies/')) }}

join

Convert an array to a string with a delimiter. Example: Convert countries to comma-separated string
  • Input: nodes.start.countries = ["US", "CA", "UK", "DE"]
  • Output: "US, CA, UK, DE"
// Convert countries array to comma-separated string
{{ nodes.start.countries.join(', ') }}

map

Transform each element in an array. Example: Add company data to stakeholders
  • Input: nodes.apollo.stakeholders = [
    {"name": "John", "title": "CEO"},
    {"name": "Sarah", "title": "CTO"}
    ]
  • Company data: nodes.start.domain = "acme.com", nodes.hubspot.companyId = "12345"
  • Output: [
    {"name": "John", "title": "CEO", "domain": "acme.com", "hubspotId": "12345"},
    {"name": "Sarah", "title": "CTO", "domain": "acme.com", "hubspotId": "12345"}
    ]
// Add domain and HubSpot ID to each stakeholder
{{
  nodes.apollo.stakeholders.map(stakeholder => ({
    ...stakeholder,
    domain: nodes.start.domain,
    hubspotId: nodes.hubspot.companyId
  }))
}}

concat

Merge two arrays together. Example: Combine prospect lists
  • Input: nodes.start.countries1 = ["US", "CA"], nodes.start.countries2 = ["UK", "DE"]
  • Output: ["US", "CA", "UK", "DE"]
// Combine two country lists
{{ nodes.start.countries1.concat(nodes.start.countries2) }}

Date and time

new Date()

Create a timestamp. Example: Get current timestamp
  • Output: "2024-01-15T10:30:45.123Z"
// Get current date
{{ new Date() }}

toLocaleDateString()

Format date in localized format. Example: Format current date
  • Output: "1/15/2024"
// Format date as MM/DD/YYYY
{{ new Date().toLocaleDateString() }}

Mathematical operations

Basic arithmetic

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

// Calculate percentage
{{ (nodes.start.wins / nodes.start.total) * 100 }}

Common patterns

Conditional logic

Use ternary operators for simple conditions. Example: Set priority based on score
  • Input: nodes.start.score = 85
  • Output: "High Priority"
// Set status based on score
{{ nodes.start.score > 80 ? 'High Priority' : 'Standard' }}

Object property access

Access nested properties using dot notation. Example: Extract the city from a nested address
  • Input: nodes.start = {
    "user": {
    "address": {
    "city": "San Francisco"}
    }}
  • Output: "San Francisco"
// Get user's city
{{ nodes.start.user.address.city }}

Null checking

Safely access properties that might not exist. Example: Get theme with default fallback
  • Input: nodes.start = {
    "user": {
    "preferences": null
    }}
  • Output: "default"
// Safely access optional property
{{ nodes.start.user?.preferences?.theme }}

Tips

  • Access the autocomplete feature while writing expressions using/ on your keyboard
  • You cannot use a node’s outputs inside an expression when the node isn’t connected to the prior nodes in the execution logic
  • Always wrap expressions in double curly brackets: {{ expression }}
  • Use dot notation to access nested object properties
  • Arrays are zero-indexed in JavaScript