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

246
Views
¿Cómo eliminar una matriz dentro de una matriz en React JS?

Digamos que tengo (son más datos que solo identificación y descripción, pero como ejemplo, acabo de agregarlos):

 tempArray: [ {id:"L-2627", description: "Book1"}, {id:"L-62961", description: "Book2"}, {id:"L-70605", description: "Book3"} ]

y cuando quiero borrar algo tengo que chequearlo y cuando lo chequeo me sale el ID, digamos que es el primero L-2627:

ingrese la descripción de la imagen aquí

si los reviso todos, obtengo todas las identificaciones

ingrese la descripción de la imagen aquí

entonces me gustaría eliminar digamos el primero y debería verse así:

 tempArray: [ {id:"L-62961", description: "Book2"}, {id:"L-70605", description: "Book3"} ]

Cómo logro esto ?

ACTUALIZAR mejor visual: (estoy usando tempLibrosData para jugar con otra variable y no la principal después de que funcione con tempLibrosData, luego usaré la variable principal)

Esto es lo que tengo:

 let librosData = data[0].data let tempLibrosData = librosData;

La función Eliminar

 onClick={() => { const selectedIDs = new Set(selectionModel); librosData.filter((x) => selectedIDs.has(x.id)).map( x => { console.log(x.id) //This prints the ID (in this case L-2627) const res = tempLibrosData.filter(e => e.id != x.id) console.log(tempLibrosData) // This should print the final result and is printing so far all of them }) }}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Puedes usar Array.filter :

 const idToRemove = "L-2627" tempArray = [ {id:"L-2627", description: "Book1"}, {id:"L-62961", description: "Book2"}, {id:"L-70605", description: "Book3"} ] const res = tempArray.filter(e => e.id != idToRemove) console.log(res)

about 4 years ago · Juan Pablo Isaza Report

0

Use MobX y cree y decore un modelo de vista y la vista (use mobx-react para eso).

Entonces es banal.

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!