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

123
Views
How to change field names in a nested JavaScript object?

When I need to pass data from other people's API to the frontend, sometimes I need to change some field names. For example, Here's the data I received:

const backend = [
  {
    id: 1,
    posts: [
      {
        id: 1,
        title: 'hello'
      }
    ],
  },
  {
    id: 2,
    posts: [
      {
        id: 3,
        title: 'world'
      }
    ]
  }
]

How to change all field names id into values. Should I refer to use some recursive deep clone functions and modify the key of field accordingly?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Do like this

const backend = [
  {
    id: 1,
    posts: [
      {
        id: 1,
        title: 'hello'
      }
    ],
  },
  {
    id: 2,
    posts: [
      {
        id: 3,
        title: 'world'
      }
    ]
  }
]
const newbackend = backend.map(({
  id: values,
  ...rest
}) => ({
  values,
  ...rest
}));

console.log(newbackend)

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!