无法从数组中删除元素

I am making a todolist app and I face the problem that I am unable to delete the task from the array. Each task is given an id number. I used splice method but its not working.

function getInput() {
  let task = inputEl.value;
  task.id = ids
  let taskList = () => {
    return `<li class="list-group-item" id="${ids+1}">
          <div class="input-group-prepend">
              <div class="input-group-text check-box-back">
                 <input onClick="strike(${ids+1})" id="checkline" class="check-box" type="checkbox" aria-label="Radio button for following text input">
              </div>
                <h5 class="list-text">${task}</h3>
                <div class="deletebox">
                <button onclick="deletetask(${ids+1})" id="delete" type="button" class="btn btn-danger deletebtn">DELETE</button>
                </div>
        </div>
         </li>`;
  };

  taskarr.push(taskList());
  //tableEl.innerHTML = taskarr;
  ids += 1;
  taskListHTML = taskarr

  inputEl.value = '';
  inputEl.focus();

  displayList(taskarr);
}

//function to delete item
function deletetask(e) {
  var a = document.getElementById(e);
  a.remove();
  console.log(e);
  for (var i = 0; i < taskarr.length; i++) {
    if (taskarr[i].id === e) {
      taskarr.splice(i, 1);
      break;
    }
  }
  displayList(taskarr);
}

addEl.addEventListener('click', getInput);
评论