-4

I'm making a to-do-list in JavaScript and HTML using unordered list. When a task is added, it's saved in local storage as follows:

tasksInLocalStorage.push({
  index: `${tasksInLocalStorage.length}`,
  value: input.value,
  isDone: false
});
localStorage.setItem("tasks", JSON.stringify(tasksInLocalStorage));

When I click on a specific li element, I apply a class to it using element.classList.toggle('name').
When the class is applied, I want the isDone: false inside the object in the array to be set to true, but I don't know how to reach the correct object.

gre_gor
  • 6,115
  • 9
  • 39
  • 46
cunami
  • 1
  • 2
    Find the task by `index` and change it? – gre_gor May 28 '22 at 14:48
  • 1
    There is an API ...[`localStorage.getItem()`](https://developer.mozilla.org/en-US/docs/Web/API/Storage/getItem)... which you can use to read from localStorage.. However, you will have a different problem... How will you identify a particular element from `tasksInLocalStorage` once read back from localStorage... so that you can set some state back into that particular element and then save it again into localStorage with updated state? – Nalin Ranjan May 28 '22 at 14:50
  • Does this answer your question? [How can I access and process nested objects, arrays or JSON?](https://stackoverflow.com/questions/11922383/how-can-i-access-and-process-nested-objects-arrays-or-json) – jabaa May 28 '22 at 15:22

0 Answers0