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

160
Views
¿Cómo fusionar objetos y agregarlos a una nueva matriz si los valores de los objetos son los mismos usando JavaScript?

Tengo este tipo de datos, mi objetivo es encontrar los mismos valores de request_id en los objetos dados, fusionarlos en un objeto y agregar su unique_id en una matriz. ¿Cómo puedo obtener este resultado?

 let fakeData = { "622b1e4a8c73d4742a66434e212":{ request_id: "1", uique_id:'001' }, "622b1e4a8c73d4742a6643423e54":{ request_id: "1", uique_id:'002' }, "622b1e4a8c73d4742a6643423e23":{ request_id: "2", uique_id:'003' }, } let parts = [] for (const property in fakeData) { console.log(fakeData[property]); } //Result should be // [{request_id:'1', values:["001, 002"]}, {request_id:'2', values:["003"]}]

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

0

Puede iterar sobre todos los valores usando Object.values() y array#reduce . En el grupo array#reduce basado en request_id en un objeto y extraiga todos los valores de estos objetos usando Object.values() .

 const fakeData = { "622b1e4a8c73d4742a66434e212": { request_id: "1", uique_id: '001' }, "622b1e4a8c73d4742a6643423e54": { request_id: "1", uique_id: '002' }, "622b1e4a8c73d4742a6643423e23": { request_id: "2", uique_id: '003' }, }, output = Object.values(fakeData).reduce((r, {request_id, uique_id}) => { r[request_id] ??= {request_id, values: []}; r[request_id].values.push(uique_id); return r; },{}), result = Object.values(output); console.log(result);
 .as-console-wrapper { max-height: 100% !important; top: 0; }

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!