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

209
Views
How do I convert a string with a first name and last name to an object w/ properties of {firstName: "string first name", lastName: "string last name}?

function convertNameToObject(string) {

    let obj = {};
    obj.firstName = ;
    obj.lastName = ;
    return obj;

}
console.log(convertNameToObject("Harry Potter"));

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

0

Just split on the space character.

function convertNameToObject(string) {
    const [firstName, lastName] = string.split(" ");
    return { firstName, lastName };
}
console.log(convertNameToObject("Harry Potter"));

about 4 years ago · Juan Pablo Isaza Report

0

Little improved version that originally was provided by @Samathingamajig.

In the body of function there is IIFE expression.

function convertNameToObject(string) {
    return (([firstName, lastName]) => ({firstName, lastName}))(string.split(" "))

}
console.log(convertNameToObject("Harry Potter"));

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!