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

122
Views
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 answers
Answer question

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 Report

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 Report

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 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!