function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Phuc 2Phuc 2 

Aura component parse string to get first last name

Hello ALl,
Within an aura component how do you parse/split a string?
I need to sperate a string value that has the full name into 
First Name and last Name  
Thank you,
P
Best Answer chosen by Phuc 2
SwethaSwetha (Salesforce Developers) 
HI Phuc,
You can use the split function in your lightning component as suggested in https://salesforce.stackexchange.com/questions/237499/why-i-use-split-function-have-error-in-lightning-component-like-this

Make sure you add a toString method convert the field to String. 

Also see https://salesforce.stackexchange.com/questions/195052/how-to-use-split-function-inside-an-expression-in-lightning-component

Thanks

All Answers

SwethaSwetha (Salesforce Developers) 
HI Phuc,
You can use the split function in your lightning component as suggested in https://salesforce.stackexchange.com/questions/237499/why-i-use-split-function-have-error-in-lightning-component-like-this

Make sure you add a toString method convert the field to String. 

Also see https://salesforce.stackexchange.com/questions/195052/how-to-use-split-function-inside-an-expression-in-lightning-component

Thanks
This was selected as the best answer
mukesh guptamukesh gupta
Hi phuc,

Please follow below code:-
 
var FullName="Mukesh Gupta";
var details=[]
var details=FullName.split(' ');
console.log("FirstName="+details[0])
console.log("LastName="+details[1]);

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh