Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

115
Views
Get an object of multiple person first and last name comma separeted

So in my JS I have 3 variables like so;

fName = 'Lili, Abraham';
lName = 'Vabiens, Lincoln';
email = 'l@vbiens.com, a@lcln.com'

And I'd like to get an object of the person details like so.

So, in the end, I'd have this:

{ firstName: "Lily", lastName: "Vabiens", fullName: : "Lily Vabiens", email: "l@vbiens.com" },
{ firstName: "Abraham", lastName: "Lincoln", fullName: : "Abraham Lincoln", email: "a@lcln.com" },

What would be the smartest way of going about this?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Now considering the lengths of each attribute of data is same, the following code will work.

First we split the strings into arrays.

fName = 'Lili, Abraham';
lName = 'Vabiens, Lincoln';
email = 'l@vbiens.com, a@lcln.com'

f_name_list = fName.split(', ');
l_name_list = lName.split(', ');
email_list = email.split(', ');

Then we loop and append an object to an array.

let result = [];

for ( let i = 0; i < f_name_list.length; i++ ) {
  result.push({
    firstName: f_name_list[i],
    lastName: l_name_list[i],
    fullName: f_name_list[i] + ' ' + l_name_list[i],
    email: email_list[i]
  });
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!