单击按钮删除阵列项目

我如何在点击时移除项目。这是我的按钮值

<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'].

我想在单击时删除数组上的项目

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);
}
评论