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

154
Views
Making an object from multiple properties

I have an array of objects like below :

var ara = [
 {
    Name: 'Lionel',
    Age: 32,
    Positions: ['Winger', 'Midfield', 'Striker']
 },
 {
    Name: 'Neymar',
    Age: 28,
    Position: ['Winger', 'Striker']
 }
]

I want this :

var profiles = [
    {
        Identity: {Name: 'Lionel', Age: 32},
        Positions: ['Winger', 'Midfield', 'Striker'],
    },
    {        
        Identity: {Name: 'Neymar', Age: 28},
        Positions: ['Winger', 'Striker']
];
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can simply use an .map() function and reformat your array

var ara = [
 {
    Name: 'Lionel',
    Age: 32,
    Positions: ['Winger', 'Midfield', 'Striker']
 },
 {
    Name: 'Neymar',
    Age: 28,
    Positions: ['Winger', 'Striker']
 }
]


var profiles = ara.map((obj) => {
  return {
    Identity:{
      Name: obj.Name,
      Age: obj.Age
    },
    Positions: obj.Positions
  }
})

console.log(profiles)

about 4 years ago · Juan Pablo Isaza Report

0

Destructure with rest in object destructuring ... and build a new object with short hand properties.

const
    ara = [{ Name: 'Lionel', Age: 32, Positions: ['Winger', 'Midfield', 'Striker'] }, { Name: 'Neymar', Age: 28, Position: ['Winger', 'Striker'] }],
    profiles = ara.map(({ Positions, ...Identity }) =>
        ({ Identity, Positions })
    );

console.log(profiles);
.as-console-wrapper { max-height: 100% !important; top: 0; }

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!