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 :)
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);