Split first name and second name of a form field

Hey guys,

I am migrating from integromat to n8n and need to split the first name and second name of a form received via webhook and capitalize the words.

Any ideas how I can do this on n8n?

Thanks in advance

Note: In integromat the solution I use is shown below:

Hey @bbarbi!

Welcome to the community :sparkling_heart:

Can you share the output that you receive? If you’re familiar with JavaScript, you can use the Function node and write custom code to do this :slight_smile:

Thank you very much Harshil :raised_hands:

I was already considering that function node would be the best solution for this problem. Unfortunately my javascript knowledge is very basic. I will study about it. :+1:

No worries :slight_smile:

If you face any issues, or need any help, feel free to post it here :slight_smile:

I don’t know if it’s correct, but it worked. :raised_hands: :raised_hands: :raised_hands:

Learning code little by little. :heart:

N8N is awesome!

Yaay! This is amazing. I am so happy that you’re learning to code as well :wink:

FYI. If it is a smaller code snippet and you are referencing it once you can use it in the Expression editor as well. Below is an example that will help you understand it better

The first Set node (Set name) is creating mock data. The second Set node (Split name), uses the .split() method and references the first and last name.

I hope this helps :slight_smile:

Yes, it helps a lot. :heart:

Thank you for your help @harshil1712 :facepunch:

Hello @bbarbi another approach is to using directly in the expression like this in cases when you have more than two words in the value of name.

firstname = {{$json[“Name”].split(" “)[0]}}
lastname = {{$json[“Name”].split(” ").slice(1).join(’ ')}}

Thank you @rodrigoscdc :facepunch: :+1:

Thank you! That’s exaclty what I needed :pray: