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

127
Vistas
javascript json data map issue
[
  {
    personId: 1,
    name: 'John',
    surName: 'Sur',
    bookId: 1,
    bookName: 'Lord of the ring',
    updated_at: 2022-01-24T19:20:53.742Z,
    deliver__date: null
  },
  {
    personId: 1,
    name: 'John',
    surName: 'Sur',
    bookId: 2,
    bookName: 'Fableheaven',
    updated_at: 2022-01-24T19:21:57.813Z,
    deliver__date: null
  },
 {
    personId: 1,
    name: 'John',
    surName: 'Sur',
    bookId: 3,
    bookName: 'Some Book',
    updated_at: 2022-01-24T19:21:57.813Z,
    deliver__date: null
  }
]

I wanna do this json data like this [{ personId:1 name:"John", surName:"Sur", lend:{..rest} }]

but I can't how can do this thanks for help for now.

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

It seems like you want to use "Rest Parameters" by the language of your question. More Info

const input = [
  {
    personId: 1,
    name: 'John',
    surName: 'Sur',
    bookId: 1,
    bookName: 'Lord of the ring',
    updated_at: '2022-01-24T19:20:53.742Z',
    deliver__date: null
  },
  {
    personId: 1,
    name: 'John',
    surName: 'Sur',
    bookId: 2,
    bookName: 'Fableheaven',
    updated_at: '2022-01-24T19:21:57.813Z',
    deliver__date: null
  },
 {
    personId: 1,
    name: 'John',
    surName: 'Sur',
    bookId: 3,
    bookName: 'Some Book',
    updated_at: '2022-01-24T19:21:57.813Z',
    deliver__date: null
  }
];

const output = input.map(({personId, name, surName, ...rest}) => ({
  personId,
  name,
  surName,
  rest
}));

console.log(output);

about 4 years ago · Juan Pablo Isaza Denunciar

0

Im not sure if I got your requirements correctly, but do you mean this?

const obj = [ { personId: 1, name: 'John', surName: 'Sur', bookId: 1, bookName: 'Lord of the ring', updated_at: '2022-01-24T19:20:53.742Z', deliver__date: null }, { personId: 1, name: 'John', surName: 'Sur', bookId: 2, bookName: 'Fableheaven', updated_at: '2022-01-24T19:21:57.813Z', deliver__date: null }, { personId: 1, name: 'John', surName: 'Sur', bookId: 3, bookName: 'Some Book', updated_at: '2022-01-24T19:21:57.813Z', deliver__date: null } ]

console.log(obj.map((el)=>({personId: el.personId, name: el.name, surName: el.surName, 
lend: {bookId: el.bookId, bookName: el.bookName, updated_at: el.updated_at, deliver__date: el.deliver__date}})));

about 4 years ago · Juan Pablo Isaza Denunciar

0

result = arr.map(el => {
   return {
     personId: el.personId,
     name: el.name,
     surName: el.surName,
     lend: {
       bookId: el.bookId,
       bookNme: el.bookName,
       updated_at: el.updated_at,
       deliver__date: el.deliver__date
      } 
    })
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