Delete Key from Array

Just wondering if there is a node that can remove one or more key (value pair(s)) from an array?

Hi @dickhoning

You can use the code node to delete those. Example:

delete item.json.field

Also with the n8n-nodes-renamekeys-advanced - npm you can specify the keys you want to keep. But yeah that does require a custom node.
I do not know of a way without using the code node or custom nodes.

1 Like

or for an array in the (new) Code node:

for (const item of $input.all()) {
  delete item.json.[field]
}

return $input.all();

where:
• [field] is the name of the key you want to delete …
• the input is an array …
• and with ‘Run Once for All Items’ …

This information is really essential, as the Code function is all about context, which is not always (or rather mostly not :wink: ) obvious at first sight …

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.