Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

199
Vistas
forEach() is not a function

I am getting an error during the page load I think true code but console declare warning forEach() is not a function Help me please if you have time. Thank you for the help.

function duty() {
  let tasks;

  if (localStorage.getItem("tasks") === null) {
    tasks = [];
  } else {
    tasks = JSON.parse(localStorage.getItem("tasks"));
  }

  tasks.forEach(function (item) {
    const li = document.createElement("li");

    li.className = "collection-item";

    li.appendChild(document.createTextNode(item));

    const link = document.createElement("a");

    link.className = "delete-item secondary-content";
    link.innerHTML = "<i class='fas fa-trash'></i>";

    li.appendChild(link);

    taskList.appendChild(li);
  });
}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

tasks = JSON.parse(localStorage.getItem('tasks'));

Result of this line is not an Array it's an object and forEach works only on the Array.

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use Object.values(obj) to convert the object to an array, then proceed with forEach()

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda