Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

141
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda