Estaba trabajando en un proyecto Js que toma notas a través de un área de texto usando un botón con un evento de clic. He almacenado el valor del área de texto en almacenamiento local en la tecla "notas". Entonces, todo lo que hice fue que analicé el valor de txtarea y luego lo encadené y lo analicé más para un cambio de html, pero ahora, cuando aplico un bucle forach en la forma de notas PARSED, muestra un error: no puedo leer los porps de nulo lectura foreach.
console.log("Welcome To MagicNotes"); // if users adds a note add it to the local storage let addbtn = document.getElementById("addbtn"); // let notes = document.getElementById('notes') // add a eventlistener -- click addbtn.addEventListener("click", function (e) { //firstly we get/define the values let addtxt = document.getElementById("addtxt"); //get the textarea by its id let notes = localStorage.getItem("notes"); //get a notes array in the local storage // here comes the operation part --> // do nothing if value is null if (notes == null) { notesObj = []; // but parse if finds a string } else { notesObj = JSON.parse(notes); //use notesObj to store obj values of "notes" //JSON.parse is used to convert a text to object } // now update the value in that obj notesObj.push(addtxt.value); localStorage.setItem("notes", JSON.stringify(notesObj)); //now stringify notesObj and use it in local storage addtxt.value = ""; //to clear the txtarea after adding a note console.log(notesObj); showNotes(); }); function showNotes() { let notes = localStorage.getItem("notes"); if (notes = null) { notesObj = []; } else { notesObj = JSON.parse(notes); } let html = ""; notesObj.forEach (function (element, index) { html += ` <div id="notes" class="noteCard my-2 mx-2 card"> <div class="container my-1"> <div class="card" style="width: 100%;"> <div class="card-body"> <h5 class="card-title">Note ${index + 1}</h5> <p class="card-text">${element}</p> <button href="#" class="btn btn-warning">Delete</button> </div> </div> </div> `; }); let notesElm = document.getElementById("notes"); if (notes.length == 0) { notesElm.innerHTML = html; } }