Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kholisrag/3afa2f11fe985d9ff41c67f8991b6e54 to your computer and use it in GitHub Desktop.
Save kholisrag/3afa2f11fe985d9ff41c67f8991b6e54 to your computer and use it in GitHub Desktop.
n8n Code node - Javascript to combine multiple items to 1 items after merging using Append
// This script merges all incoming items into a single object.
const combinedObject = {};
// Loop through each item that flows into this node.
for (const item of items) {
// Merge the properties of the current item's JSON into our single object.
// Object.assign() copies all properties from the source (item.json)
// to the target (combinedObject).
// If a key already exists, it will be overwritten by the last one found.
Object.assign(combinedObject, item.json);
}
// n8n expects an array of items as the output.
// We return an array containing just our single, combined object.
return [{
json: combinedObject
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment