N8N JavaScript Functions

Complete reference guide with all 117 built-in functions and practical examples

⌘K
117
Functions
10
Categories
117
Showing

average()

Array Functions

Returns the average value of elements in an array

{{ [1, 2, 3, 4, 5].average() }}
3

chunk(size)

Array Functions

Splits arrays into chunks with a specified size

{{ [1, 2, 3, 4, 5].chunk(2) }}
[[1, 2], [3, 4], [5]]

compact()

Array Functions

Removes empty values from the array

{{ [1, null, 2, '', 3].compact() }}
[1, 2, 3]

difference(arr)

Array Functions

Returns elements in base array that aren't in comparison array

{{ [1, 2, 3].difference([2, 3, 4]) }}
[1]

intersection(arr)

Array Functions

Returns elements present in both arrays

{{ [1, 2, 3].intersection([2, 3, 4]) }}
[2, 3]

first()

Array Functions

Returns the first element of the array

{{ ['apple', 'banana', 'cherry'].first() }}
'apple'

isEmpty()

Array Functions

Checks if the array has no elements

{{ [].isEmpty() }}
true

isNotEmpty()

Array Functions

Checks if the array has elements

{{ [1, 2].isNotEmpty() }}
true

last()

Array Functions

Returns the last element of the array

{{ ['apple', 'banana', 'cherry'].last() }}
'cherry'

max()

Array Functions

Returns the highest value in an array

{{ [1, 5, 3, 9, 2].max() }}
9

merge(arr)

Array Functions

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()

Array Functions

Gets the minimum value from a number array

{{ [1, 5, 3, 9, 2].min() }}
1

pluck(fieldName)

Array Functions

Returns array of objects with specified field names

{{ [{name: 'John', age: 30}].pluck('name') }}
[{name: 'John'}]

randomItem()

Array Functions

Returns a random element from an array

{{ ['red', 'blue', 'green'].randomItem() }}
'blue' (random)

removeDuplicates(key?)

Array Functions

Removes duplicate elements from array

{{ [1, 2, 2, 3, 3].removeDuplicates() }}
[1, 2, 3]

renameKeys(from, to)

Array Functions

Renames matching keys in array objects

{{ [{oldName: 'John'}].renameKeys('oldName', 'newName') }}
[{newName: 'John'}]

smartJoin(keyField, nameField)

Array Functions

Creates object from key-value pairs in array

{{ [{key: 'name', value: 'John'}].smartJoin('key', 'value') }}
{name: 'John'}

sum()

Array Functions

Returns total sum of all values in number array

{{ [1, 2, 3, 4, 5].sum() }}
15

toJsonString()

Array Functions

Converts array to JSON string

{{ [1, 2, 3].toJsonString() }}
'[1,2,3]'

union(arr)

Array Functions

Concatenates arrays and removes duplicates

{{ [1, 2].union([2, 3, 4]) }}
[1, 2, 3, 4]

unique(key?)

Array Functions

Removes duplicates from array

{{ [1, 1, 2, 2, 3].unique() }}
[1, 2, 3]

isEmpty()

Object Functions

Checks if the object has no key-value pairs

{{ {}.isEmpty() }}
true

merge(object)

Object Functions

Merges two objects, base object takes precedence

{{ {a: 1, b: 2}.merge({b: 3, c: 4}) }}
{a: 1, b: 2, c: 4}

hasField(fieldName)

Object Functions

Checks if object has a given field

{{ {name: 'John', age: 30}.hasField('name') }}
true

removeField(key)

Object Functions

Removes a field from the object

{{ {name: 'John', age: 30}.removeField('age') }}
{name: 'John'}

removeFieldsContaining(value)

Object Functions

Removes fields with specified value

{{ {a: 'test', b: 'keep', c: 'test'}.removeFieldsContaining('test') }}
{b: 'keep'}

keepFieldsContaining(value)

Object Functions

Keeps only fields with specified value

{{ {a: 'keep', b: 'remove', c: 'keep'}.keepFieldsContaining('keep') }}
{a: 'keep', c: 'keep'}

compact()

Object Functions

Removes empty values from object

{{ {a: 1, b: null, c: '', d: 2}.compact() }}
{a: 1, d: 2}

toJsonString()

Object Functions

Converts object to JSON string

{{ {name: 'John', age: 30}.toJsonString() }}
'{"name":"John","age":30}'

urlEncode()

Object Functions

Transforms object into URL parameter list

{{ {name: 'John Doe', age: 30}.urlEncode() }}
'name=John%20Doe&age=30'

base64Encode()

String Functions

Encodes string as base64

{{ 'Hello World'.base64Encode() }}
'SGVsbG8gV29ybGQ='

base64Decode()

String Functions

Decodes base64 string to normal string

{{ 'SGVsbG8gV29ybGQ='.base64Decode() }}
'Hello World'

extractDomain()

String Functions

Extracts domain from URL string

{{ 'https://www.example.com/path'.extractDomain() }}
'www.example.com'

extractEmail()

String Functions

Extracts email from string

{{ 'Contact us at info@example.com today'.extractEmail() }}
'info@example.com'

extractUrl()

String Functions

Extracts URL from string

{{ 'Visit https://example.com for more'.extractUrl() }}
'https://example.com'

extractUrlPath()

String Functions

Extracts path from URL

{{ 'https://example.com/orders/123'.extractUrlPath() }}
'/orders/123'

hash(algo?)

String Functions

Returns hashed string with specified algorithm

{{ 'password'.hash('md5') }}
'5e884898da28047...'

isDomain()

String Functions

Checks if string is a valid domain

{{ 'example.com'.isDomain() }}
true

isEmail()

String Functions

Checks if string is a valid email

{{ 'user@example.com'.isEmail() }}
true

isEmpty()

String Functions

Checks if string is empty

{{ ''.isEmpty() }}
true

isNotEmpty()

String Functions

Checks if string has content

{{ 'Hello'.isNotEmpty() }}
true

isNumeric()

String Functions

Checks if string contains only digits

{{ '12345'.isNumeric() }}
true

isUrl()

String Functions

Checks if string is a valid URL

{{ 'https://example.com'.isUrl() }}
true

parseJson()

String Functions

Parses string as JSON object

{{ '{"name":"John"}' .parseJson() }}
{name: 'John'}

quote(mark?)

String Functions

Wraps string in quotation marks

{{ 'Hello'.quote() }}
'"Hello"'

removeMarkdown()

String Functions

Removes Markdown formatting from string

{{ '**bold** text'.removeMarkdown() }}
'bold text'

replaceSpecialChars()

String Functions

Replaces non-ASCII characters with ASCII

{{ 'café'.replaceSpecialChars() }}
'cafe'

removeTags()

String Functions

Removes HTML/XML tags from string

{{ '<p>Hello</p>'.removeTags() }}
'Hello'

toBoolean()

String Functions

Converts string to boolean

{{ 'true'.toBoolean() }}
true

toDateTime()

String Functions

Converts string to Luxon date object

{{ '2025-06-30'.toDateTime() }}
DateTime object

toFloat()

String Functions

Converts string to decimal number

{{ '3.14'.toFloat() }}
3.14

toInt()

String Functions

Converts string to integer

{{ '42'.toInt() }}
42

toSentenceCase()

String Functions

Converts string to sentence case

{{ 'hello world'.toSentenceCase() }}
'Hello world'

toSnakeCase()

String Functions

Converts string to snake_case

{{ 'Hello World'.toSnakeCase() }}
'hello_world'

toTitleCase()

String Functions

Converts string to Title Case

{{ 'hello world'.toTitleCase() }}
'Hello World'

toWholeNumber()

String Functions

Converts string to whole number

{{ '42.7'.toWholeNumber() }}
43

urlDecode(entireString?)

String Functions

Decodes URL-encoded string

{{ 'Hello%20World'.urlDecode() }}
'Hello World'

urlEncode(entireString?)

String Functions

Encodes string for URL usage

{{ 'Hello World'.urlEncode() }}
'Hello%20World'

beginningOf(unit)

Date Functions

Returns date at beginning of time period

{{ $now.beginningOf('month') }}
First day of current month

endOfMonth()

Date Functions

Returns last day of the month

{{ $now.endOfMonth() }}
Last day of current month

extract(datePart)

Date Functions

Extracts specific part from date

{{ $now.extract('year') }}
2025

format(fmt)

Date Functions

Formats date according to format string

{{ $now.format('yyyy-MM-dd') }}
'2025-06-30'

isBetween(date1, date2)

Date Functions

Checks if date is between two dates

{{ $now.isBetween('2025-01-01', '2025-12-31') }}
true

isDst()

Date Functions

Checks if date is in Daylight Savings Time

{{ $now.isDst() }}
true/false

isInLast(n, unit)

Date Functions

Checks if date is within last N time units

{{ $now.isInLast(7, 'days') }}
true

isWeekend()

Date Functions

Checks if date falls on weekend

{{ $now.isWeekend() }}
true/false

minus(n, unit)

Date Functions

Subtracts time from date

{{ $now.minus(7, 'days') }}
Date 7 days ago

plus(n, unit)

Date Functions

Adds time to date

{{ $now.plus(7, 'days') }}
Date 7 days from now

toDateTime()

Date Functions

Converts to Luxon DateTime object

{{ $now.toDateTime() }}
DateTime object

ceil()

Number Functions

Rounds number up to whole number

{{ 4.2.ceil() }}
5

floor()

Number Functions

Rounds number down to whole number

{{ 4.8.floor() }}
4

format(locales?, options?)

Number Functions

Formats number according to locale and options

{{ 1234.5.format('en-US') }}
'1,234.5'

isEven()

Number Functions

Checks if number is even

{{ 4.isEven() }}
true

isOdd()

Number Functions

Checks if number is odd

{{ 5.isOdd() }}
true

round(decimalPlaces?)

Number Functions

Rounds number to specified decimal places

{{ 4.567.round(2) }}
4.57

toBoolean()

Number Functions

Converts number to boolean (0 = false, others = true)

{{ 0.toBoolean() }}
false

toDateTime(format?)

Number Functions

Converts number to Luxon date object

{{ 1719705600000.toDateTime('ms') }}
DateTime object

$json

Built-in Variables

Access current node's JSON data

{{ $json.email }}
user@example.com

$input

Built-in Variables

Access input data from current node

{{ $input.all() }}
All input items

$binary

Built-in Variables

Access binary data from current node

{{ $binary.data }}
Binary file data

$now

Built-in Variables

Current timestamp as Luxon object

{{ $now.format('yyyy-MM-dd') }}
2025-06-30

$today

Built-in Variables

Today's date at midnight

{{ $today.format('yyyy-MM-dd') }}
2025-06-30

$vars

Built-in Variables

Access custom variables

{{ $vars.myVariable }}
Variable value

$workflow

Built-in Variables

Access workflow metadata

{{ $workflow.name }}
My Workflow

$execution

Built-in Variables

Access execution metadata

{{ $execution.id }}
exec_123456

$runIndex

Built-in Variables

Current execution run index

{{ $runIndex }}
0

$itemIndex

Built-in Variables

Current item index being processed

{{ $itemIndex }}
2

$prevNode

Built-in Variables

Access previous node information

{{ $prevNode.name }}
HTTP Request

$env

Built-in Variables

Access environment variables

{{ $env.NODE_ENV }}
production

$nodeVersion

Built-in Variables

Version of the current node

{{ $nodeVersion }}
1.0

$version

Built-in Variables

N8N version information

{{ $version }}
1.0.5

$secrets

Built-in Variables

Access external secrets

{{ $secrets.apiKey }}
secret_value

$("nodeName").all()

Node Access Functions

Get all items from specified node

{{ $("HTTP Request").all() }}
All items from HTTP Request node

$("nodeName").first()

Node Access Functions

Get first item from specified node

{{ $("HTTP Request").first() }}
First item from HTTP Request node

$("nodeName").last()

Node Access Functions

Get last item from specified node

{{ $("HTTP Request").last() }}
Last item from HTTP Request node

$("nodeName").item

Node Access Functions

Get linked item from specified node

{{ $("HTTP Request").item }}
Linked item from HTTP Request node

$("nodeName").params

Node Access Functions

Get parameters from specified node

{{ $("HTTP Request").params }}
Node parameters

$("nodeName").context

Node Access Functions

Get context from specified node

{{ $("HTTP Request").context }}
Node context data

$("nodeName").itemMatching()

Node Access Functions

Get matching item from specified node

{{ $("HTTP Request").itemMatching(0) }}
Matching item from node

$("nodeName").isExecuted

Node Access Functions

Check if specified node was executed

{{ $("HTTP Request").isExecuted }}
true/false

$input.item

Input/Output Functions

Current input item being processed

{{ $input.item.json.name }}
Item data

$input.all()

Input/Output Functions

All input items for current node

{{ $input.all() }}
Array of all input items

$input.first()

Input/Output Functions

First input item for current node

{{ $input.first() }}
First input item

$input.last()

Input/Output Functions

Last input item for current node

{{ $input.last() }}
Last input item

$input.params

Input/Output Functions

Input parameters for current node

{{ $input.params }}
Node parameters

$input.context.noItemsLeft

Input/Output Functions

Check if no more items to process

{{ $input.context.noItemsLeft }}
true/false

$execution.id

Execution Context Functions

Unique execution identifier

{{ $execution.id }}
exec_abc123

$execution.mode

Execution Context Functions

Execution mode (test or production)

{{ $execution.mode }}
production

$execution.resumeUrl

Execution Context Functions

Resume URL for Wait node

{{ $execution.resumeUrl }}
https://app.n8n.io/webhook/...

$execution.customData

Execution Context Functions

Custom execution data

{{ $execution.customData.key }}
Custom value

$prevNode.name

Execution Context Functions

Name of previous node

{{ $prevNode.name }}
HTTP Request

$prevNode.outputIndex

Execution Context Functions

Output index of previous node

{{ $prevNode.outputIndex }}
0

$prevNode.runIndex

Execution Context Functions

Run index of previous node

{{ $prevNode.runIndex }}
0

$getWorkflowStaticData(type)

Workflow Functions

Access workflow static data

{{ $getWorkflowStaticData('global').lastRun }}
Static data value

$workflow.id

Workflow Functions

Workflow unique identifier

{{ $workflow.id }}
workflow_123

$workflow.name

Workflow Functions

Workflow name

{{ $workflow.name }}
My Automation Workflow

$workflow.active

Workflow Functions

Whether workflow is active

{{ $workflow.active }}
true

N8N Functions Reference

Complete reference guide for all N8N JavaScript functions to supercharge your workflow automation

Official Documentation
Updated for N8N v1.100.1 • 117 Functions