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

133
Vistas
Filtering all objects apart from one and changing their values

I have an object which I want to filter only by shops:

const items = {
    "cars": {
        "porshe": {
            "active": true
        }
    },
    "shops": {
        "primark": {
            "active": true
        },
        "zara": {
            "active": true
        },
        "nike": {
            "active": true
        }
    }
}

 const filtered = Object.keys(items)
                .filter((key) => !['cars'].includes(key))
                .reduce((shops, key) => {
                    shops[key] = items[key];
                    return shops[key];
                }, {});
       
console.log(filtered);
                

Now I want to update all active values for "primark", "zara" and "nike" to active:false, and update my items object.

I have no idea how I can achieve that, I will be very grateful for every replies :)

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

0

Sometimes you only need simple for in loop for object updates which is faster.

for (let key in items.shops) {
  items.shops[key].active = false
}

Now you can check it with console.log(items);

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