N8N JavaScript Functions
Complete reference guide with all 117 built-in functions and practical examples
average()
Returns the average value of elements in an array
{{ [1, 2, 3, 4, 5].average() }}
3
chunk(size)
Splits arrays into chunks with a specified size
{{ [1, 2, 3, 4, 5].chunk(2) }}
[[1, 2], [3, 4], [5]]
compact()
Removes empty values from the array
{{ [1, null, 2, '', 3].compact() }}
[1, 2, 3]
difference(arr)
Returns elements in base array that aren't in comparison array
{{ [1, 2, 3].difference([2, 3, 4]) }}
[1]
intersection(arr)
Returns elements present in both arrays
{{ [1, 2, 3].intersection([2, 3, 4]) }}
[2, 3]
first()
Returns the first element of the array
{{ ['apple', 'banana', 'cherry'].first() }}
'apple'
isEmpty()
Checks if the array has no elements
{{ [].isEmpty() }}
true
isNotEmpty()
Checks if the array has elements
{{ [1, 2].isNotEmpty() }}
true
last()
Returns the last element of the array
{{ ['apple', 'banana', 'cherry'].last() }}
'cherry'
max()
Returns the highest value in an array
{{ [1, 5, 3, 9, 2].max() }}
9
merge(arr)
Merges two object-arrays by combining key-value pairs
{{ [{a: 1}, {b: 2}].merge([{c: 3}, {d: 4}]) }}
[{a: 1, c: 3}, {b: 2, d: 4}]
min()
Gets the minimum value from a number array
{{ [1, 5, 3, 9, 2].min() }}
1
pluck(fieldName)
Returns array of objects with specified field names
{{ [{name: 'John', age: 30}].pluck('name') }}
[{name: 'John'}]
randomItem()
Returns a random element from an array
{{ ['red', 'blue', 'green'].randomItem() }}
'blue' (random)
removeDuplicates(key?)
Removes duplicate elements from array
{{ [1, 2, 2, 3, 3].removeDuplicates() }}
[1, 2, 3]
renameKeys(from, to)
Renames matching keys in array objects
{{ [{oldName: 'John'}].renameKeys('oldName', 'newName') }}
[{newName: 'John'}]
smartJoin(keyField, nameField)
Creates object from key-value pairs in array
{{ [{key: 'name', value: 'John'}].smartJoin('key', 'value') }}
{name: 'John'}
sum()
Returns total sum of all values in number array
{{ [1, 2, 3, 4, 5].sum() }}
15
toJsonString()
Converts array to JSON string
{{ [1, 2, 3].toJsonString() }}
'[1,2,3]'
union(arr)
Concatenates arrays and removes duplicates
{{ [1, 2].union([2, 3, 4]) }}
[1, 2, 3, 4]
unique(key?)
Removes duplicates from array
{{ [1, 1, 2, 2, 3].unique() }}
[1, 2, 3]
isEmpty()
Checks if the object has no key-value pairs
{{ {}.isEmpty() }}
true
merge(object)
Merges two objects, base object takes precedence
{{ {a: 1, b: 2}.merge({b: 3, c: 4}) }}
{a: 1, b: 2, c: 4}
hasField(fieldName)
Checks if object has a given field
{{ {name: 'John', age: 30}.hasField('name') }}
true
removeField(key)
Removes a field from the object
{{ {name: 'John', age: 30}.removeField('age') }}
{name: 'John'}
removeFieldsContaining(value)
Removes fields with specified value
{{ {a: 'test', b: 'keep', c: 'test'}.removeFieldsContaining('test') }}
{b: 'keep'}
keepFieldsContaining(value)
Keeps only fields with specified value
{{ {a: 'keep', b: 'remove', c: 'keep'}.keepFieldsContaining('keep') }}
{a: 'keep', c: 'keep'}
compact()
Removes empty values from object
{{ {a: 1, b: null, c: '', d: 2}.compact() }}
{a: 1, d: 2}
toJsonString()
Converts object to JSON string
{{ {name: 'John', age: 30}.toJsonString() }}
'{"name":"John","age":30}'
urlEncode()
Transforms object into URL parameter list
{{ {name: 'John Doe', age: 30}.urlEncode() }}
'name=John%20Doe&age=30'
base64Encode()
Encodes string as base64
{{ 'Hello World'.base64Encode() }}
'SGVsbG8gV29ybGQ='
base64Decode()
Decodes base64 string to normal string
{{ 'SGVsbG8gV29ybGQ='.base64Decode() }}
'Hello World'
extractDomain()
Extracts domain from URL string
{{ 'https://www.example.com/path'.extractDomain() }}
'www.example.com'
extractEmail()
Extracts email from string
{{ 'Contact us at info@example.com today'.extractEmail() }}
'info@example.com'
extractUrl()
Extracts URL from string
{{ 'Visit https://example.com for more'.extractUrl() }}
'https://example.com'
extractUrlPath()
Extracts path from URL
{{ 'https://example.com/orders/123'.extractUrlPath() }}
'/orders/123'
hash(algo?)
Returns hashed string with specified algorithm
{{ 'password'.hash('md5') }}
'5e884898da28047...'
isDomain()
Checks if string is a valid domain
{{ 'example.com'.isDomain() }}
true
isEmail()
Checks if string is a valid email
{{ 'user@example.com'.isEmail() }}
true
isEmpty()
Checks if string is empty
{{ ''.isEmpty() }}
true
isNotEmpty()
Checks if string has content
{{ 'Hello'.isNotEmpty() }}
true
isNumeric()
Checks if string contains only digits
{{ '12345'.isNumeric() }}
true
isUrl()
Checks if string is a valid URL
{{ 'https://example.com'.isUrl() }}
true
parseJson()
Parses string as JSON object
{{ '{"name":"John"}' .parseJson() }}
{name: 'John'}
quote(mark?)
Wraps string in quotation marks
{{ 'Hello'.quote() }}
'"Hello"'
removeMarkdown()
Removes Markdown formatting from string
{{ '**bold** text'.removeMarkdown() }}
'bold text'
replaceSpecialChars()
Replaces non-ASCII characters with ASCII
{{ 'café'.replaceSpecialChars() }}
'cafe'
removeTags()
Removes HTML/XML tags from string
{{ '<p>Hello</p>'.removeTags() }}
'Hello'
toBoolean()
Converts string to boolean
{{ 'true'.toBoolean() }}
true
toDateTime()
Converts string to Luxon date object
{{ '2025-06-30'.toDateTime() }}
DateTime object
toFloat()
Converts string to decimal number
{{ '3.14'.toFloat() }}
3.14
toInt()
Converts string to integer
{{ '42'.toInt() }}
42
toSentenceCase()
Converts string to sentence case
{{ 'hello world'.toSentenceCase() }}
'Hello world'
toSnakeCase()
Converts string to snake_case
{{ 'Hello World'.toSnakeCase() }}
'hello_world'
toTitleCase()
Converts string to Title Case
{{ 'hello world'.toTitleCase() }}
'Hello World'
toWholeNumber()
Converts string to whole number
{{ '42.7'.toWholeNumber() }}
43
urlDecode(entireString?)
Decodes URL-encoded string
{{ 'Hello%20World'.urlDecode() }}
'Hello World'
urlEncode(entireString?)
Encodes string for URL usage
{{ 'Hello World'.urlEncode() }}
'Hello%20World'
beginningOf(unit)
Returns date at beginning of time period
{{ $now.beginningOf('month') }}
First day of current month
endOfMonth()
Returns last day of the month
{{ $now.endOfMonth() }}
Last day of current month
extract(datePart)
Extracts specific part from date
{{ $now.extract('year') }}
2025
format(fmt)
Formats date according to format string
{{ $now.format('yyyy-MM-dd') }}
'2025-06-30'
isBetween(date1, date2)
Checks if date is between two dates
{{ $now.isBetween('2025-01-01', '2025-12-31') }}
true
isDst()
Checks if date is in Daylight Savings Time
{{ $now.isDst() }}
true/false
isInLast(n, unit)
Checks if date is within last N time units
{{ $now.isInLast(7, 'days') }}
true
isWeekend()
Checks if date falls on weekend
{{ $now.isWeekend() }}
true/false
minus(n, unit)
Subtracts time from date
{{ $now.minus(7, 'days') }}
Date 7 days ago
plus(n, unit)
Adds time to date
{{ $now.plus(7, 'days') }}
Date 7 days from now
toDateTime()
Converts to Luxon DateTime object
{{ $now.toDateTime() }}
DateTime object
ceil()
Rounds number up to whole number
{{ 4.2.ceil() }}
5
floor()
Rounds number down to whole number
{{ 4.8.floor() }}
4
format(locales?, options?)
Formats number according to locale and options
{{ 1234.5.format('en-US') }}
'1,234.5'
isEven()
Checks if number is even
{{ 4.isEven() }}
true
isOdd()
Checks if number is odd
{{ 5.isOdd() }}
true
round(decimalPlaces?)
Rounds number to specified decimal places
{{ 4.567.round(2) }}
4.57
toBoolean()
Converts number to boolean (0 = false, others = true)
{{ 0.toBoolean() }}
false
toDateTime(format?)
Converts number to Luxon date object
{{ 1719705600000.toDateTime('ms') }}
DateTime object
$json
Access current node's JSON data
{{ $json.email }}
user@example.com
$input
Access input data from current node
{{ $input.all() }}
All input items
$binary
Access binary data from current node
{{ $binary.data }}
Binary file data
$now
Current timestamp as Luxon object
{{ $now.format('yyyy-MM-dd') }}
2025-06-30
$today
Today's date at midnight
{{ $today.format('yyyy-MM-dd') }}
2025-06-30
$vars
Access custom variables
{{ $vars.myVariable }}
Variable value
$workflow
Access workflow metadata
{{ $workflow.name }}
My Workflow
$execution
Access execution metadata
{{ $execution.id }}
exec_123456
$runIndex
Current execution run index
{{ $runIndex }}
0
$itemIndex
Current item index being processed
{{ $itemIndex }}
2
$prevNode
Access previous node information
{{ $prevNode.name }}
HTTP Request
$env
Access environment variables
{{ $env.NODE_ENV }}
production
$nodeVersion
Version of the current node
{{ $nodeVersion }}
1.0
$version
N8N version information
{{ $version }}
1.0.5
$secrets
Access external secrets
{{ $secrets.apiKey }}
secret_value
$("nodeName").all()
Get all items from specified node
{{ $("HTTP Request").all() }}
All items from HTTP Request node
$("nodeName").first()
Get first item from specified node
{{ $("HTTP Request").first() }}
First item from HTTP Request node
$("nodeName").last()
Get last item from specified node
{{ $("HTTP Request").last() }}
Last item from HTTP Request node
$("nodeName").item
Get linked item from specified node
{{ $("HTTP Request").item }}
Linked item from HTTP Request node
$("nodeName").params
Get parameters from specified node
{{ $("HTTP Request").params }}
Node parameters
$("nodeName").context
Get context from specified node
{{ $("HTTP Request").context }}
Node context data
$("nodeName").itemMatching()
Get matching item from specified node
{{ $("HTTP Request").itemMatching(0) }}
Matching item from node
$("nodeName").isExecuted
Check if specified node was executed
{{ $("HTTP Request").isExecuted }}
true/false
$input.item
Current input item being processed
{{ $input.item.json.name }}
Item data
$input.all()
All input items for current node
{{ $input.all() }}
Array of all input items
$input.first()
First input item for current node
{{ $input.first() }}
First input item
$input.last()
Last input item for current node
{{ $input.last() }}
Last input item
$input.params
Input parameters for current node
{{ $input.params }}
Node parameters
$input.context.noItemsLeft
Check if no more items to process
{{ $input.context.noItemsLeft }}
true/false
$execution.id
Unique execution identifier
{{ $execution.id }}
exec_abc123
$execution.mode
Execution mode (test or production)
{{ $execution.mode }}
production
$execution.resumeUrl
Resume URL for Wait node
{{ $execution.resumeUrl }}
https://app.n8n.io/webhook/...
$execution.customData
Custom execution data
{{ $execution.customData.key }}
Custom value
$prevNode.name
Name of previous node
{{ $prevNode.name }}
HTTP Request
$prevNode.outputIndex
Output index of previous node
{{ $prevNode.outputIndex }}
0
$prevNode.runIndex
Run index of previous node
{{ $prevNode.runIndex }}
0
$getWorkflowStaticData(type)
Access workflow static data
{{ $getWorkflowStaticData('global').lastRun }}
Static data value
$workflow.id
Workflow unique identifier
{{ $workflow.id }}
workflow_123
$workflow.name
Workflow name
{{ $workflow.name }}
My Automation Workflow
$workflow.active
Whether workflow is active
{{ $workflow.active }}
true