Is n8n has node like reduce()

Hi,all
my data is like this

[
  {"query": "a"},
  {"query": "b"},
  {"query": "c"}
]

how can I get this with n8n node,I just need a,a+b,a+b+c,can I use loop or anything else to make this happen?

[
  {"query": "a"},
  {"query": "ab"},
  {"query": "abc"}
]

Thank you very much

Information on your n8n setup

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hey @Anrufen , the method reduce() typically implies the output just

[
  {
    "query": "abc"
  }
]

no intermediate values like “ab”.

If that is what you are after, use Summarize node with Concatenate aggregation as below

Sorry, maybe I use the wrong descrption with reduce, I wan’t to get a,a+b,a+b+c for each row,like Cumulative Sum or Cumulative Concatenation,may the functioncode is like this

const inputArray = items.map(item => item.json);

let cumulativeArray = [];
let cumulativeString = "";

inputArray.forEach(item => {
  cumulativeString += item.query;
  cumulativeArray.push({ query: cumulativeString });
});

return cumulativeArray.map(item => ({ json: item }));

Is there any existed n8n node can make this result?

Hey @Anrufen , no, I do not think there is such a node. However, you did a great job with Code node to achieve that. Thanks for sharing.

Building such an cumulative logic with other nodes will make it more complex than what you have done with Code node.

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