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

220
Views
Elimine los duplicados de la matriz de objetos y almacene valores no duplicados en la matriz

Necesito fusionar una matriz de entregas que tienen notas, ¿cómo eliminaría el objeto duplicado pero mantendría la cadena de notas y la almacenaría en una matriz para el objeto no duplicado?

Clave comienza el número de entrega:

 "data": [ { "deliveryNumber": "0000001", "deliveryDate": "2021-10-01T00:00:00.000Z", "dateBeginProcess": null, "dateFinishedProcess": null, "status": "", "notes": "Note 1" }, { "deliveryNumber": "0000001", "deliveryDate": "2021-10-01T00:00:00.000Z", "dateBeginProcess": null, "dateFinishedProcess": null, "status": "Ready", "notes": "Note 2" }, { "deliveryNumber": "0000002", "deliveryDate": "2021-10-01T14:21:00.000Z", "dateBeginProcess": null, "dateFinishedProcess": null, "status": "Ready", "notes": null } ]

dentro

 "data": [ { "deliveryNumber": "0000001", "deliveryDate": "2021-10-01T00:00:00.000Z", "dateBeginProcess": null, "dateFinishedProcess": null, "status": "Ready", "notes": ["Note 1", "Note 2"] }, { "deliveryNumber": "0000002", "deliveryDate": "2021-10-01T14:21:00.000Z", "dateBeginProcess": null, "dateFinishedProcess": null, "status": "Ready", "notes": null } ]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede usar Array.prototype.forEach() para recorrer la matriz de notas. Si se encuentra una nota dos veces, sume sus notas.

 const notes = [ { "deliveryNumber": "0000001", "deliveryDate": "2021-10-01T00:00:00.000Z", "dateBeginProcess": null, "dateFinishedProcess": null, "status": "", "notes": "Note 1" }, { "deliveryNumber": "0000001", "deliveryDate": "2021-10-01T00:00:00.000Z", "dateBeginProcess": null, "dateFinishedProcess": null, "status": "Ready", "notes": "Note 2" }, { "deliveryNumber": "0000002", "deliveryDate": "2021-10-01T14:21:00.000Z", "dateBeginProcess": null, "dateFinishedProcess": null, "status": "Ready", "notes": null } ] let filteredArray = [] notes.forEach(note => { let noteFound = filteredArray.find(el => el.deliveryNumber === note.deliveryNumber) if(noteFound){ // not first encounter // add notes together noteFound.notes.push(note.notes) }else{ // first encounter // make notes an array note.notes = [note.notes||''] filteredArray.push(note) } }) console.log(filteredArray)

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!