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

197
Views
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 answers
Answer question

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 Report

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 Report
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!