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

164
Views
Hacer un objeto a partir de múltiples propiedades

Tengo una serie de objetos como a continuación:

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

Quiero esto :

 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

Simplemente puede usar una función .map() y reformatear su matriz

 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

Desestructurar con descanso en la desestructuración de objetos ... y construir un nuevo objeto con propiedades de mano abreviada .

 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!