I am currently working on creating an array with different properties for each day of the week. Here is what I have so far:
const [fullData, setFullData] = useState([{index:-1,exercise:''}])
My goal is to allow users to choose exercises for a specific day, such as Monday, and store the selected exercises along with the corresponding weekday index. The desired output would look something like this:
[{index:1,exercise:'exercise1'},{index:1,exercise:'exercise2'}]
The challenge lies in properly integrating the existing exercise array and weekday variable into the code. The exercise values are stored in another array:
const [exerciseValues, setExerciseValues] = useState([]);
And the weekday index is stored as a regular variable:
let selectedWeekday_Index:number;
I have tried various solutions found on stackoverflow but have been unable to successfully implement them into my code. My latest attempt produced non-functional code. If further clarification is needed, feel free to ask and I will provide more details.
const acceptExercises = () => {
let selectedElements = [...exerciseValues]
let savedData = [...fullData]
selectedElements.forEach(element => {
let copyData=savedData.map(item=>({
[item.exercise]:element,
[item.index]:selectedWeekday_Index
}))
setFullData(copyData)
});
}