Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

156
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda