Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
El valor está definido pero aún muestra "no se pueden leer las propiedades de nulo" (foreach)

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; } }
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!