So I'm trying to switch the value of selected from whatever. Value is the opposite. It's for a checkbox. Idk maybe lack sleep but I'm having the hardest time trying to figure this out. Here's the data structure. It's JSON with arrays that have objects.
[
[
{
"module": "string",
"selected": false,
"name": "title",
"points": [{
"category": "category1",
"description": "desc1",
"provided": "provided1"
},
{
"category": "category1",
"description": "desc",
"provided": "something"
}
]
},
{
"module": "string",
"selected": false,
"name": "title_one",
"points": [{
"category": "category1",
"description": "desc1",
"provided": "provided1"
},
{
"category": "category1",
"description": "desc",
"provided": "something"
}
]
},
],
[...],
[...]
]
My closest attempt but it's the wrong format
//checked value is the information of the checkbox and valuesArr is the entire array
function toggleCheck(checkedValue, valuesArr) {
return {
value: valuesArr.map((module, i, ...values) => {
return [
...values,
(values[i] = module.map((x, j, ...transObj) => ({
...transObj,
selected: x.name === checkedValue.name ?
!values[i][j].selected :
values[i][j].selected,
}))),
];
}),
};
}
^^^ That above structure made it so it's
[
[
[ {},
{},
{}
],
[...],
[...]
]
]
I need
[
[ {},
{},
{}
],
[...],
[...]
]