0

I am getting this error it is showing listarr.forEach is not a function.

let newLiTag='';

listArr.forEach((element, index) =>{
  newLiTag+= `<li> ${element} <span class="check" onclick="check(${index})"> <i class="fas fa-check"></i></span>

 <span onclick = "modify(${index})"><i class="fas fa-edit"></i></span>

 <span onclick = "deleteTask(${index})"><i class="fas fa-trash"></i></span> </li>`;
});
Mark
  • 143,421
  • 24
  • 428
  • 436
haseen
  • 17
  • 4
  • when posting a question, put `\`\`\`` before your code and `\`\`\`` after your code will make it easier to read – 0nepeop1e Feb 09 '22 at 16:14
  • 1
    You have not provided enough context in this code snippet for a neat answer. Please post information about where `listArr` is created and wherever it has values assigned to it. Otherwise, these questions may help: [1](https://stackoverflow.com/questions/31096596/why-is-foreach-not-a-function-for-this-object/31096661) [2](https://stackoverflow.com/questions/35969974/foreach-is-not-a-function-error-with-javascript-array) [3](https://stackoverflow.com/questions/46334292/foreach-not-a-function-javascript) – AndrewF Feb 12 '22 at 02:50

1 Answers1

0

Please check if you have declared the variable listArr. Example:

let newLiTag='';
const listArr = []; // Add variable listArr here

listArr.forEach((element, index) =>{
    // Do things here
});
rhemmuuu
  • 1,147
  • 2
  • 5
  • 19
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 10 '22 at 06:49