Anrufen
September 25, 2024, 11:43am
1
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:
n8n
September 25, 2024, 11:43am
2
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:
ihortom
September 25, 2024, 7:14pm
3
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
Anrufen
September 27, 2024, 10:48am
4
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?
ihortom
September 27, 2024, 4:50pm
5
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.
system
Closed
December 26, 2024, 4:50pm
6
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.