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

151
Visualizações
How can i remove an object from array of objects in app.delete using express

i would like to remove an object of specified id: I tried by this:

app.delete("/:id", (req, res) => {
  const id = req.params.id;
  try {
    const filtered = games.filter(function (el) {
      return el.id !== id;
    });

    res.send({ rest: filtered });
  } catch (error) {
    res.send({ error: error.message });
  }
});

This although, does not remove the object in games array of objects, but returns the filtered array. Does anyone have an idea on that?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

filter does not change the original array, it creates a new array based on the filter you provided.

You could set the games array to the now filtered array, and that would remove the object.

games = games.filter(function (el) {
  return el.id !== id;
});

res.send({ rest: games });
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