Sort
Sorts array elements in ascending order. Supports both numeric and string arrays with locale-aware string sorting.
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.
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 sort. Must contain only numbers or only strings.
Options
- Language Code - Locale code for string sorting (e.g., "en_US", "tr_TR", "de_DE"). Default: "en_US". This affects how strings are compared and sorted based on language-specific rules.
- Ignore Case - When enabled, sorts strings case-insensitively (e.g., "apple" and "Apple" are treated the same). Default: false.
Outputs
- Array - The sorted array in ascending order.
How It Works
The Sort node arranges array elements in ascending order based on their data type. When executed, the node:
- Receives an array through the Array input
- Validates that the array is not null and not empty
- Determines the data type of the first element (number or string)
- Validates that all elements are of the same type
- For numbers:
- Sorts in ascending numeric order
- For strings:
- Uses locale-specific collation based on Language Code
- Optionally ignores case if Ignore Case is enabled
- Sorts according to language-specific alphabetical rules
- Returns the sorted array
- Handles thread-safe operations when working with Global or Flow scope variables
Requirements
- Valid array as input (not null or empty)
- All elements must be of the same type (all numbers OR all strings)
- Language code must be valid (e.g., "en_US", "fr_FR", "ja_JP")
Error Handling
The node will return specific errors in the following cases:
- Array is null: "Input array cannot be empty"
- Array is empty: "Input array cannot be empty"
- Mixed types: "(value) is not a number" or "(value) is not a string"
- Invalid language code: "language code (code) is not valid"
Data Type Support
Numbers
- Integers:
[5, 2, 8, 1]→[1, 2, 5, 8] - Decimals:
[3.14, 2.71, 1.41]→[1.41, 2.71, 3.14] - Negative numbers:
[-5, 3, -2, 0]→[-5, -2, 0, 3]
Strings
- Alphabetical:
["zebra", "apple", "mango"]→["apple", "mango", "zebra"] - Case-sensitive (default):
["Apple", "apple", "APPLE"]→["APPLE", "Apple", "apple"] - Case-insensitive:
["Apple", "apple", "APPLE"]→["apple", "Apple", "APPLE"](order may vary for equal values)
Usage Examples
Example 1: Sort Numeric Prices
Sort product prices in ascending order:
- Array:
[29.99, 15.50, 99.99, 5.00, 45.00] - Result:
[5.00, 15.50, 29.99, 45.00, 99.99] - Use for displaying products by price
Example 2: Sort Customer Names (Case-Insensitive)
Sort customer names alphabetically:
- Array:
["Smith", "anderson", "Brown", "DAVIS"] - Language Code:
"en_US" - Ignore Case:
true - Result:
["anderson", "Brown", "DAVIS", "Smith"] - All names sorted alphabetically regardless of case
Example 3: Sort Product IDs
Sort numeric product IDs:
- Array:
[1005, 1001, 1003, 1009, 1002] - Result:
[1001, 1002, 1003, 1005, 1009] - Use for ordered processing or reporting
Example 4: Locale-Specific String Sorting
Sort German strings with locale rules:
- Array:
["Äpfel", "Zebra", "Bär", "Apfel"] - Language Code:
"de_DE" - Result: Sorted according to German alphabetical rules
- Handles special characters like ä, ö, ü correctly
Example 5: Sort Scraped Data
Sort scraped prices for comparison:
- Scrape prices from multiple websites →
{{msg.prices}} - Convert prices to numbers using Array.Convert
- Sort prices in ascending order
- First element = lowest price
- Last element = highest price
Example 6: Sort Search Results by Relevance Score
Sort results by relevance:
- Extract relevance scores →
[85, 92, 78, 95, 88] - Sort in ascending order →
[78, 85, 88, 92, 95] - Reverse using Array.Reverse →
[95, 92, 88, 85, 78] - Now sorted by highest relevance first
Tips for Effective Use
- Ascending order only: Sort only provides ascending order; use Array.Reverse for descending
- Uniform types: All elements must be the same type (all numbers OR all strings)
- Case sensitivity: Default is case-sensitive; enable Ignore Case for case-insensitive sorting
- Locale awareness: Use appropriate Language Code for international text
- Empty arrays: Cannot sort empty arrays
- Use Array.Convert to ensure consistent data types before sorting
- Combine with Array.Reverse for descending order
- For complex object sorting, extract the field to sort by first
- Thread-safe when using Global or Flow scopes
- The original array is modified and returned sorted
Common Use Cases
- Sorting product prices (lowest to highest)
- Alphabetizing customer names or product lists
- Ordering IDs or reference numbers
- Ranking items by score or rating
- Organizing data chronologically (using numeric timestamps)
- Sorting search results by relevance
- Preparing data for reporting (ordered presentation)
- Finding minimum/maximum values (first/last after sorting)
- Implementing priority-based processing
- Data deduplication and comparison (easier with sorted data)
Language Codes
Common language codes for string sorting:
- English (US):
en_US - English (UK):
en_GB - German:
de_DE - French:
fr_FR - Spanish:
es_ES - Turkish:
tr_TR - Japanese:
ja_JP - Chinese (Simplified):
zh_CN - Russian:
ru_RU - Arabic:
ar_SA
Sorting Patterns
Ascending Order (Default)
Input: [50, 20, 80, 10]
Output: [10, 20, 50, 80]
Descending Order (with Reverse)
1. Sort: [50, 20, 80, 10] → [10, 20, 50, 80]
2. Reverse: [10, 20, 50, 80] → [80, 50, 20, 10]
Case-Sensitive String Sort
Input: ["apple", "Apple", "APPLE", "banana"]
Ignore Case: false
Output: ["APPLE", "Apple", "apple", "banana"]
Case-Insensitive String Sort
Input: ["apple", "Apple", "APPLE", "banana"]
Ignore Case: true
Output: ["apple", "Apple", "APPLE", "banana"]
(equivalent values maintain original order)
Integration Examples
Example: Find Min and Max Values
1. Array: [45, 12, 89, 23, 67]
2. Sort array → [12, 23, 45, 67, 89]
3. Get first element (index 0) → 12 (minimum)
4. Get last element (index length-1) → 89 (maximum)
Example: Top N Results
1. Array of scores: [85, 92, 78, 95, 88, 72, 90]
2. Sort array → [72, 78, 85, 88, 90, 92, 95]
3. Reverse array → [95, 92, 90, 88, 85, 78, 72]
4. Slice first 3 elements → [95, 92, 90]
5. Result: Top 3 scores
Example: Price Comparison Workflow
1. Scrape prices from multiple sites
2. Store in array: [29.99, 25.50, 32.00, 24.99]
3. Sort prices → [24.99, 25.50, 29.99, 32.00]
4. Get lowest price: array[0] → 24.99
5. Get highest price: array[length-1] → 32.00
6. Calculate average
7. Generate comparison report
Example: Alphabetical Customer Processing
1. Get customer names: ["Smith", "Johnson", "Williams", "Anderson"]
2. Sort with en_US locale and ignore case
3. Result: ["Anderson", "Johnson", "Smith", "Williams"]
4. Process customers in alphabetical order
5. Better organization and findability
Example: Priority-Based Task Sorting
1. Extract task priorities: [3, 1, 4, 2, 1, 5]
2. Sort priorities → [1, 1, 2, 3, 4, 5]
3. Reverse for highest priority first → [5, 4, 3, 2, 1, 1]
4. Process tasks in priority order
Common Errors and Solutions
Error: "Input array cannot be empty"
Cause: The array is null or has no elements.
Solutions:
- Check that the array is properly initialized
- Validate array has data before sorting
- Use Array.GetLength to check size first
Error: "(value) is not a number"
Cause: Array contains mixed types or non-numeric values when numbers are expected.
Solutions:
- Ensure all elements are numbers
- Use Array.Convert to convert strings to numbers first
- Filter out non-numeric values before sorting
- Check data extraction logic
Error: "(value) is not a string"
Cause: Array contains mixed types or non-string values when strings are expected.
Solutions:
- Ensure all elements are strings
- Use Array.Convert to convert numbers to strings first
- Filter out non-string values before sorting
Error: "language code (code) is not valid"
Cause: Invalid or unsupported language code provided.
Solutions:
- Use standard language codes (e.g., "en_US", "de_DE")
- Check language code format (language_COUNTRY)
- Default to "en_US" if unsure
- Verify language code is supported
Performance Notes
- Sorting large arrays may take time
- Time complexity: O(n log n) for most cases
- String sorting is slower than numeric sorting
- Locale-aware string sorting has additional overhead
- Consider chunking very large arrays for better performance