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

112
Views
javascript function to get list of objects and return new key with new value in new array

for privacy I explain simple example . function that get personal list and return new key with new value like below:

personalList = [{
        firstName: "elena",
        lastName: "zakharova"
    },
    {
        firstName: "alex",
        lastName: "farmanda"
    },
    {
        firstName: "mike",
        lastName: "kenan"
    }]

output should be like this:

desiredList =[{fullname :'elena zakhrova'},{fullname :'alex farmanda'}, fullname : 'mike kenan']

tried some ways but unfortunately did not get answer

Any solutions would be appreciated.

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You can use map

const personalList = [{
        firstName: "elena",
        lastName: "zakharova"
    },
    {
        firstName: "alex",
        lastName: "farmanda"
    },
    {
        firstName: "mike",
        lastName: "kenan"
    }]
    
    
console.log(personalList.map(({firstName,lastName}) => ({fullName: `${firstName} ${lastName}`})))

about 4 years ago · Santiago Trujillo Report

0

Here's How I Would Solve This Using For Loop. You Can Also Use Maps Like How @R4ncid Has Explained

var desiredlist = []
var personalList = [{
        firstName: "elena",
        lastName: "zakharova"
    },
    {
        firstName: "alex",
        lastName: "farmanda"
    },
    {
        firstName: "mike",
        lastName: "kenan"
    }]

for (i=0;i<personalList.length;i++){
        desiredlist.push({"fullname":personalList[i].firstName + " " + personalList[i].lastName})}
console.log(desiredlist)

about 4 years ago · Santiago Trujillo 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!