Let's say I have this object:
{
b954WYBCC4YbsMM36trawb00xZ32: { activity1: "pending", activity2: "pending" },
pby0CAqQ1hTlagIqBTQf6l2Ti9L2: { activity1: "pending", activity2: "pending" }
}
where the first keys are IDs from a database. I want to be able to change the values of activity1 and activity2 based on an array:
// 'data' is the object mentioned above.
const usersHaveSpecialContentAssigned = [true, false];
Object.values(data).forEach((item, index) => {
const arrayActivityProgress = Object.values(item as string[]);
if (usersHaveSpecialContentAssigned[index] === false) {
arrayActivityProgress.forEach((progress) => {
progress = 'unassigned';
console.log(progress);
});
}
});
As you can see, my goal is to change the values of activity1 and activity2 if the corresponding value in usersHaveSpecialContentAssigned is false.
The end result based on the example above should look like this:
{
b954WYBCC4YbsMM36trawb00xZ32: { activity1: "pending", activity2: "pending" },
pby0CAqQ1hTlagIqBTQf6l2Ti9L2: { activity1: "unassigned", activity2: "unassigned" }
}
How can I achieve this? My current approach doesn't update the values.
datayou need to do so explicitly ie.item.activity1 = 'unassigned'const o = [1]; let [a] = o; a = 3; console.log(o[0]);it logs 1 not 3. Assigning to a function parameter in theforEachcallback doesn't change the array.