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

93
Views
Convierta recursivamente los campos de un objeto de camelCase a MAYÚSCULAS

He intentado convertir recursivamente los campos de un objeto de camelCase a MAYÚSCULAS.

Por alguna razón, no funcionará, he intentado muchas formas diferentes desde aquí en stackoverflow.

Agradecería toda la ayuda, gracias.

 const o = { KeyFirst: "firstVal", KeySecond: [ { KeyThird: "thirdVal", }, ], KeyFourth: { KeyFifth: [ { KeySixth: "sixthVal", }, ], }, }; function renameKeys(obj) { return Object.keys(obj).reduce((acc, key) => { const value = obj[key]; const modifiedKey = `${key[0].toLowerCase()}${key.slice(1)}`; if (Array.isArray(value)) { return { ...acc, ...{ [modifiedKey]: value.map(renameKeys) }, }; } else if (typeof value === "object") { return renameKeys(value); } else { return { ...acc, ...{ [modifiedKey]: value }, }; } }, {}); } console.log(renameKeys(o));
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede recorrer recursivamente el objeto y transformar las claves para que estén en mayúsculas.

 const o = { KeyFirst: { KeySecond: "secondVal" }, KeyThird: [{ KeyFourth: "fourthVal" }], KeyFifth: { KeySixth: [{ KeySeventh: "seventhVal" }], }, }; function renameKeys(obj) { if (Array.isArray(obj)) { return obj.map((o) => renameKeys(o)); } else if (typeof obj === "object" && obj !== null) { return Object.entries(obj).reduce( (r, [k, v]) => ({ ...r, [k.toUpperCase()]: renameKeys(v) }), {} ); } else { return obj; } } console.log(renameKeys(o));

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!