I need to get my checkboxes in todo list read from object in array if task is complete or not. And stay checked when they're complete and unchecked or not.
const todos = [
{
id: 1,
title: 'Nakupit',
description: 'Mlieko, syr, vajcia',
completed: false,
},
{
id: 2,
title: 'Umyt auto',
description: '+ povysavat',
completed: true,
},
]
This is the array and i tried on checkbox something like this. And variations, unable to get it work and changing array or value from array making checkbox ,checked, if complete
toDoCheckbox.addEventListener('click', () => {
if (toDoCheckbox.checked = true) {
return todos.completed === true
} else {
return todos.completed === false
}
});
Can anyone help with it?
You can modify the
todosstate by looking it up by itsidand flipping itscompletedstatus.I added the button to request re-rendering. This will re-build the checkboxes using the current state.