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…
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 = e.target.parentElement.dataset.id // Get id of the button wrapping div. This won't work if you change your HTML
const project = projectArray.find(p => p.id == id) // use this to get id and name