{"record":{"id":"c534ebd02ce23f39","repo":"n8n-io/n8n","slug":"intersection-expected-array-arg-e-g-intersec","errorCode":null,"errorMessage":"intersection(): expected array arg, e.g. .intersection([1, 2, 3, 4])","messagePattern":"intersection\\(\\): expected array arg, e\\.g\\. \\.intersection\\(\\[1, 2, 3, 4\\]\\)","errorType":"exception","errorClass":"ExpressionExtensionError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/expression-runtime/src/extensions/array-extensions.ts","lineNumber":302,"sourceCode":"\tconst [others] = extraArgs;\n\tif (!Array.isArray(others)) {\n\t\tthrow new ExpressionExtensionError(\n\t\t\t'difference(): expected array arg, e.g. .difference([1, 2, 3, 4])',\n\t\t);\n\t}\n\tconst newArr: unknown[] = [];\n\tfor (const v of value) {\n\t\tif (others.findIndex((w) => isEqual(w, v)) === -1) {\n\t\t\tnewArr.push(v);\n\t\t}\n\t}\n\treturn unique(newArr, []);\n}\n\nfunction intersection(value: unknown[], extraArgs: unknown[][]): unknown[] {\n\tconst [others] = extraArgs;\n\tif (!Array.isArray(others)) {\n\t\tthrow new ExpressionExtensionError(\n\t\t\t'intersection(): expected array arg, e.g. .intersection([1, 2, 3, 4])',\n\t\t);\n\t}\n\tconst newArr: unknown[] = [];\n\tfor (const v of value) {\n\t\tif (others.findIndex((w) => isEqual(w, v)) !== -1) {\n\t\t\tnewArr.push(v);\n\t\t}\n\t}\n\tfor (const v of others) {\n\t\tif (value.findIndex((w) => isEqual(w, v)) !== -1) {\n\t\t\tnewArr.push(v);\n\t\t}\n\t}\n\treturn unique(newArr, []);\n}\n\nfunction append(value: unknown[], extraArgs: unknown[][]): unknown[] {","sourceCodeStart":284,"sourceCodeEnd":320,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/expression-runtime/src/extensions/array-extensions.ts#L284-L320","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n{{ $json.tags.intersection('urgent') }}\n// after\n{{ $json.tags.intersection(['urgent']) }}","handlingStrategy":"validation","validationCode":"// In a Code node before the expression runs:\nconst other = $json.other;\nif (!Array.isArray(other)) {\n  throw new Error('intersection(): other must be an array, got ' + typeof other);\n}\nreturn $json;","typeGuard":"const isUnknownArray = (v: unknown): v is unknown[] => Array.isArray(v);","tryCatchPattern":null,"preventionTips":["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."],"tags":["expression","array","validation","argument-shape"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}