Javascript ToDo list

Could you please check my todolist(still not ready) :

Every time I click on the “>>” button on the right side it clears the div container and adds the testcontent of the last project added to the array.
I want to click on the ‘>>’ button and add the project that I clicked on, not always the last I added.

could someone help me. I just tried everything. I can’t solve this issue to go on…

That’s because you’re hardcoding the item to show:

  div.textContent = projectArray[projectArray.length - 1].name;
  div.setAttribute("data-id", projectArray[projectArray.length - 1].id);

projectArray[projectArray.length - 1] will always select the last item from the array.

Simplest way (not the best though) would be to check which button was clicked:

function displayTasks(e) { // Add event as an argument
  const id = // Get id of the button wrapping div. This won't work if you change your HTML
  const project = projectArray.find(p => == id) // use this to get id and name