Skip to main content

Get Length

Returns the number of elements in an array.

Common Properties

  • Name - The custom name of the node.
  • Color - The custom color of the node.
  • Delay Before (sec) - Waits in seconds before executing the node.
  • Delay After (sec) - Waits in seconds after executing node.
  • Continue On Error - Automation will continue regardless of any error. The default value is false.
info

If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.

Inputs

  • Array - The array to get the length of.

Outputs

  • Length - The number of elements in the array (integer value).

How It Works

The Get Length node counts the number of elements in an array. When executed, the node:

  1. Receives an array through the Array input
  2. Validates that the array is not null
  3. Counts the number of elements in the array
  4. Returns the count as an integer through the Length output

Requirements

  • Valid array as input (not null)
  • Empty arrays are valid and will return a length of 0

Error Handling

The node will return specific errors in the following cases:

  • Array is null: "Array cannot be null"

Usage Examples

Example 1: Validate Data Collection

Check if enough data was collected before processing:

  1. Array: {{msg.scrapedProducts}}
  2. Get Length → store in {{msg.productCount}}
  3. Add condition: If {{msg.productCount}} > 10, proceed with processing
  4. Otherwise, scrape more pages

Example 2: Loop Control

Determine loop iterations based on array size:

  1. Array: {{flow.customers}}
  2. Get Length → store in {{flow.totalCustomers}}
  3. Initialize counter: {{flow.currentIndex}} = 0
  4. Loop condition: While {{flow.currentIndex}} < {{flow.totalCustomers}}
  5. Process each customer using Array.GetElement with currentIndex
  6. Increment currentIndex after each iteration

Example 3: Progress Tracking

Display processing progress:

  1. Array: {{flow.tasks}}
  2. Get Length → store in {{flow.totalTasks}}
  3. Track completed tasks in {{flow.completedCount}}
  4. Calculate progress: {{flow.completedCount / flow.totalTasks * 100}}%
  5. Display or log progress information

Example 4: Calculate Last Index

Safely access the last element:

  1. Array: {{msg.items}}
  2. Get Length → store in {{msg.arrayLength}}
  3. Calculate last index: {{msg.arrayLength - 1}}
  4. Use Array.GetElement with index {{msg.arrayLength - 1}} to get last item
  5. Prevents index out of bounds errors

Example 5: Empty Array Validation

Check if an array has data before processing:

  1. Array: {{msg.searchResults}}
  2. Get Length → store in {{msg.resultCount}}
  3. Add condition: If {{msg.resultCount}} = 0, log "No results found"
  4. Otherwise, proceed with result processing

Example 6: Batch Processing

Divide large arrays into batches:

  1. Array: {{flow.allRecords}}
  2. Get Length → store in {{flow.totalRecords}}
  3. Set batch size: {{flow.batchSize}} = 100
  4. Calculate number of batches: {{Math.ceil(flow.totalRecords / flow.batchSize)}}
  5. Process each batch using Array.Slice

Tips for Effective Use

  • Empty arrays return a length of 0 (not an error)
  • Use before loops to set iteration limits
  • Combine with conditional nodes to validate array size
  • Calculate the last valid index: length - 1
  • Use for progress tracking and reporting
  • Essential for pagination calculations
  • Helps prevent index out of bounds errors
  • Use to validate minimum/maximum data requirements
  • Combine with Array.GetElement for safe element access
  • Store length in a variable for multiple uses (more efficient than calling multiple times)

Common Use Cases

  • Loop control and iteration management
  • Validating that arrays contain data before processing
  • Calculating array boundaries (first/last index)
  • Progress tracking and reporting
  • Batch processing calculations
  • Data quality validation (checking minimum/maximum records)
  • Pagination calculations
  • Dynamic UI updates based on data size
  • Performance monitoring (tracking data collection)
  • Conditional workflow routing based on data volume

Common Errors and Solutions

Error: "Array cannot be null"

Cause: The array input is null or undefined.

Solutions:

  • Verify that the array variable exists and is initialized
  • Check that previous nodes successfully created the array
  • Use Array.Assign to initialize empty arrays if needed
  • Add null checking before calling Get Length
  • Ensure variable names are correct and match scope

Integration Examples

Example: Safe Array Processing Pipeline

1. Get array from previous node
2. Use Get Length to check array size
3. If length > 0:
a. Use length to set up loop (0 to length-1)
b. Use Get Element to access each item
c. Process each item
4. If length = 0:
a. Log "No data to process"
b. Skip to next step

Example: Batch Processing with Progress

1. Get Length of full array → totalItems
2. Set batchSize = 50
3. Calculate batches: Math.ceil(totalItems / batchSize)
4. For each batch:
a. Calculate start: batchIndex * batchSize
b. Calculate end: start + batchSize
c. Use Array.Slice to extract batch
d. Process batch
e. Update progress: (batchIndex / totalBatches * 100)%