Hi dear friends
In my case:
I set a variable from my webhook by “set node”:
myvar = my_name_is_meysam_001
I want to split “myvar” by “_” and split it to 5 new variable like these:
var1 = my
var2 = name
var3 = is
var4 = meysam
var5 = 001
and finally use them in my next nodes.
Can anyone help me how can do this please?
Best regards;
You can split them like this:
Is there any way of doing this but instead of returning it to the same item duplicating the item with the new data?
Example:
Names: John & Bob
Right now split would be Name1=John Name2=Bob
I would want
Item 1: ID: 1 Names: John
Item 2: ID: 1 Names: Bob
Would that be possible?
Check the example below:
{
"nodes": [
{
"parameters": {},
"name": "Start",
"type": "n8n-nodes-base.start",
"typeVersion": 1,
"position": [
250,
300
]
},
{
"parameters": {
"values": {
"string": [
{
"name": "names",
"value": "John_Bob"
}
]
},
"options": {}
},
"name": "Set",
"type": "n8n-nodes-base.set",
"typeVersion": 1,
"position": [
610,
300
]
},
{
"parameters": {
"functionCode": "const results = [];\nconst names = items[0].json.names.split('_');\n\nfor (const[index, name] of names.entries()) {\n results.push({ json: { id: index, name: name } })\n}\n\nreturn results;\n\n\n"
},
"name": "Function",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
840,
300
]
}
],
"connections": {
"Start": {
"main": [
[
{
"node": "Set",
"type": "main",
"index": 0
}
]
]
},
"Set": {
"main": [
[
{
"node": "Function",
"type": "main",
"index": 0
}
]
]
}
}
}
Hmm, That does indeed return the 2 names but i ment more as in it duplicates the original row that came in so all the original data is included and the id doesnt change
Hmm, I think i got this to work with a merge node in Multiplex mode to merge the results back together