-2

I've got this function that needs to delete an item thats clicked from the array. Im sure its a simple fix but its not deleting it from the array. I think its something to do with how Im executing the function in the button? IM not entirely sure. error: TypeError: e.findIndex is not a function

const deleteClaim = (claim,value) => {
  const index = claim.findIndex(element => element === value); // 1
  const result = claim.splice(index, 1);
  return result

}

the button is

      <button onClick={(e) => deleteClaim(claim, e.target.value)} >X </button>

1 Answers1

-1

This is a small piece of code of my working project

selectedForDeleteArr is the array

function removeStatusEnum(id) {
if (selectedForDeleteArr.includes(id)) {
    let index = selectedForDeleteArr.indexOf(id)
    if (index > -1) {
        selectedForDeleteArr.splice(index, 1);
    }
    $("#sts_id" + id).removeClass("selected-to-delete")
} else {
    selectedForDeleteArr.push(id)
    $("#sts_id" + id).addClass("selected-to-delete")
}
console.log(selectedForDeleteArr)

}