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

187
Vistas
How to delete an item from my Reducer Object?

I have an object in my reducer like this :

clientData : {
1080 : [{ID : 1111,name : 'John'},{ID : 2222,name : 'Stan'},],
1090 : [{ID : 3333,name : 'Adam'},{ID : 4444,name : 'Alan'},]
}

And I want to be able to delete an item (for example Stan with 2222 ID's) The problem that is I don't have the key of my property (1080), and I don't have any idea how to achieve it. I've tried the Object.values(object1) but it convert my object to array and I lost all my architecture. Have you an idea please ?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Removing from existing objects might not be good, you can use Object.entries and filter to remove id.

If you want to change existing pass data to reducer

const data = {
  1080: [
    { ID: 1111, name: "John" },
    { ID: 2222, name: "Stan" },
  ],
  1090: [
    { ID: 3333, name: "Adam" },
    { ID: 4444, name: "Alan" },
  ],
};

const remove = (id, data) => {
  const entries = Object.entries(data);
  return entries.reduce((acc, [key, value]) => {
    const newValue = value.filter((item) => item.ID !== id);
    acc[key] = newValue;
    return acc;
    // return { ...acc, [key]: newValue };
  }, {}); // for updating existing data here
};


console.log(remove(2222, data))

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