n8n-io/n8n · error · ExpressionExtensionError
intersection(): expected array arg, e.g. .intersection([1, 2
Error message
intersection(): expected array arg, e.g. .intersection([1, 2, 3, 4])
What it means
The `.intersection([arr])` array extension returns the set-intersection of the source array and the supplied argument. It throws `ExpressionExtensionError` when the first extra argument fails `Array.isArray(...)`, because the implementation immediately calls `.findIndex(...)` on it (which would otherwise crash). The error message shows the expected call shape.
Source
Thrown at packages/@n8n/expression-runtime/src/extensions/array-extensions.ts:302
const [others] = extraArgs;
if (!Array.isArray(others)) {
throw new ExpressionExtensionError(
'difference(): expected array arg, e.g. .difference([1, 2, 3, 4])',
);
}
const newArr: unknown[] = [];
for (const v of value) {
if (others.findIndex((w) => isEqual(w, v)) === -1) {
newArr.push(v);
}
}
return unique(newArr, []);
}
function intersection(value: unknown[], extraArgs: unknown[][]): unknown[] {
const [others] = extraArgs;
if (!Array.isArray(others)) {
throw new ExpressionExtensionError(
'intersection(): expected array arg, e.g. .intersection([1, 2, 3, 4])',
);
}
const newArr: unknown[] = [];
for (const v of value) {
if (others.findIndex((w) => isEqual(w, v)) !== -1) {
newArr.push(v);
}
}
for (const v of others) {
if (value.findIndex((w) => isEqual(w, v)) !== -1) {
newArr.push(v);
}
}
return unique(newArr, []);
}
function append(value: unknown[], extraArgs: unknown[][]): unknown[] {View on GitHub (pinned to 5ac6606e81)
Solutions
- Wrap the argument in an array literal: `.intersection(['urgent'])`.
- Confirm the upstream field is actually an array (coerce in a Code node with `Array.isArray` / `split(',')`) before calling `.intersection()`.
- If you only need to test membership of a single value, use `.includes(value)` instead.
Example fix
// before
{{ $json.tags.intersection('urgent') }}
// after
{{ $json.tags.intersection(['urgent']) }} Defensive patterns
Strategy: validation
Validate before calling
// In a Code node before the expression runs:
const other = $json.other;
if (!Array.isArray(other)) {
throw new Error('intersection(): other must be an array, got ' + typeof other);
}
return $json; Type guard
const isUnknownArray = (v: unknown): v is unknown[] => Array.isArray(v);
Prevention
- Always wrap `.intersection()` arguments in array literals.
- Coerce comma-separated strings with `.split(',')` before intersecting.
- Add a Code-node assertion that upstream fields are arrays before referencing them in expressions.
When it happens
Trigger: Invoking `.intersection()` with a scalar, object, or undefined value: `{{ $json.tags.intersection('urgent') }}`, `{{ $json.ids.intersection(5) }}`, or `{{ $json.x.intersection($json.missing) }}` where `$json.missing` resolves to undefined.
Common situations: Forgetting to wrap the argument in `[...]`; pulling a single value out of an upstream node and passing it bare; referencing a field that is a comma-separated string instead of a parsed array.
Related errors
- keys and values must be arrays
- keys and values not of equal length
- removeFieldsContaining(): expected non-empty string arg
- argument of keepFieldsContaining must be a non-empty string
- Filter operator "${operator}" on key "${key}" requires a non
AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12).
Data as JSON: /api/errors/c534ebd02ce23f39.
Report an issue: GitHub.