How do I remove an item on click? This is what I currently have:
function deleteUser(name) {
var person = name;
const array = ['John','Mark','Andy'];
const index = array.indexOf(person);
if (index > -1) {
array.splice(index, 1);
}
console.log(array);
}
<button onclick="deleteUser('John')"> Delete User </button>
<button onclick="deleteUser('Mark')"> Delete User </button>
<button onclick="deleteUser('Andy')"> Delete User </button>
I can already remove value on array but I am getting different result.
Ex. When I delete on a value John. I am getting ['Mark','Andy'] but when I delete Mark I am getting ['John','Andy'].
I want to remove the item on array when it is click