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:
- Receives an array through the Array input
- Validates that the array is not null
- Counts the number of elements in the array
- 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:
- Array:
{{msg.scrapedProducts}} - Get Length → store in
{{msg.productCount}} - Add condition: If
{{msg.productCount}}> 10, proceed with processing - Otherwise, scrape more pages
Example 2: Loop Control
Determine loop iterations based on array size:
- Array:
{{flow.customers}} - Get Length → store in
{{flow.totalCustomers}} - Initialize counter:
{{flow.currentIndex}}= 0 - Loop condition: While
{{flow.currentIndex}}<{{flow.totalCustomers}} - Process each customer using Array.GetElement with currentIndex
- Increment currentIndex after each iteration
Example 3: Progress Tracking
Display processing progress:
- Array:
{{flow.tasks}} - Get Length → store in
{{flow.totalTasks}} - Track completed tasks in
{{flow.completedCount}} - Calculate progress:
{{flow.completedCount / flow.totalTasks * 100}}% - Display or log progress information
Example 4: Calculate Last Index
Safely access the last element:
- Array:
{{msg.items}} - Get Length → store in
{{msg.arrayLength}} - Calculate last index:
{{msg.arrayLength - 1}} - Use Array.GetElement with index
{{msg.arrayLength - 1}}to get last item - Prevents index out of bounds errors
Example 5: Empty Array Validation
Check if an array has data before processing:
- Array:
{{msg.searchResults}} - Get Length → store in
{{msg.resultCount}} - Add condition: If
{{msg.resultCount}}= 0, log "No results found" - Otherwise, proceed with result processing
Example 6: Batch Processing
Divide large arrays into batches:
- Array:
{{flow.allRecords}} - Get Length → store in
{{flow.totalRecords}} - Set batch size:
{{flow.batchSize}}= 100 - Calculate number of batches:
{{Math.ceil(flow.totalRecords / flow.batchSize)}} - 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)%