Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

245
Visualizações
How to delete an array inside an array in React JS?

Let's say I have (is more data than just id and description but as an example I just added those):

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

and when I want to delete something I have to check it and when I check it I get the ID, let's say is the first one L-2627:

enter image description here

if I check all of them then I get all the ids

enter image description here

then I would like to delete let's say the first one and it should look like this:

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

How do I achieve this ?

UPDATE better visual: (I'm using tempLibrosData to play with another variable and not the main after it works with tempLibrosData then I'll use the main variable)

This is what I have:

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

The Delete function

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 Respostas
Responde à pergunta

0

You can use 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 Relatório

0

Use MobX, and create and decorate a view model and the view (use mobx-react for that).

Then it's trivial.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda