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

170
Views
Cómo puedo crear un objeto con matrices anidadas de objetos por matriz de objetos anidados

lucho con este dato, tratando de convertirlo usando javascript:

 [{ rawCol: "personalemail", template: "CONTACTS", modifiedCol: "URL" }, { rawCol: "personId", template: "CONTACTS", modifiedCol: "PERSONCODE" }, { rawCol: "ssn", template: "VITALS", modifiedCol: "IDENTITY" }, { rawCol: "gender", template: "VITALS", modifiedCol: "GENDERCODE" }, { rawCol: "ethnic", template: "VITALS", modifiedCol: "ETHNICCODE" }, { rawCol: "birthdate", template: "VITALS", modifiedCol: "BIRTHDATE" }, { rawCol: "contactType", template: "OTHER", modifiedCol: "NETCONTACTTYPE" }, { rawCol: "workemail", template: "OTHER", modifiedCol: "EMAILADDRESS" }]

Quiero crear la siguiente estructura: (Quiero usar los valores de plantilla únicos de los objetos siguientes anteriores, de la siguiente manera)

 { CONTACTS: [ {rawFile: "personalemail", modifiedCol: "URL"}, {rawFile: "personId", modifiedCol: "PERSONCODE"} ], VITALS: [ {rawFile: "ssn", modifiedCol: "IDENTITY"}, {rawFile: "gender", modifiedCol: "GENDERCODE"}, {rawFile: "ethnic", modifiedCol: "ETHNICCODE"}, {rawFile: "birthdate", modifiedCol: "BIRTHDATE"}, ], OTHER: [ {rawFile: "contactType", modifiedCol: "NETCONTACTTYPE"}, {rawFile: "workemail", modifiedCol: "EMAILADDRESS"},] }

Estaré muy agradecido por una buena idea de cómo puedo lograr esto con una función o método.

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

0

const arr = [{ rawCol: "personalemail", template: "CONTACTS", modifiedCol: "URL" }, { rawCol: "personId", template: "CONTACTS", modifiedCol: "PERSONCODE" }, { rawCol: "ssn", template: "VITALS", modifiedCol: "IDENTITY" }, { rawCol: "gender", template: "VITALS", modifiedCol: "GENDERCODE" }, { rawCol: "ethnic", template: "VITALS", modifiedCol: "ETHNICCODE" }, { rawCol: "birthdate", template: "VITALS", modifiedCol: "BIRTHDATE" }, { rawCol: "contactType", template: "OTHER", modifiedCol: "NETCONTACTTYPE" }, { rawCol: "workemail", template: "OTHER", modifiedCol: "EMAILADDRESS" }]; const data = {}; arr.forEach((ar) => { data[ar.template] = [...(data[ar.template] || []), {rawFile: ar.rawCol, modifiedCol: ar.modifiedCol}] }); console.log(data)
about 4 years ago · Juan Pablo Isaza Report

0

Entonces, puedes probar este. Pero deberías leer los métodos de matriz. mapear, reducir, filtrar....

 const expectation = data.reduce((res, elem) => { const val = elem?.template delete elem.template if (!res[val]) res[val] = [] res[val].push(elem) return res }, {})
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!