我想将一个值推到数组的末尾,但由于某种原因它不起作用。当我单击按钮时,它应该将值添加到数组的末尾。然后,如果我再次单击它,它应该告诉我它仍然存在,但它只是不断推入阵列。我怎样才能让值留在数组中。
<html>
<head>
<script>
function myFunction() {
var asdf = ["a","b","c","e"];
if (asdf.indexOf("d")==-1) {
asdf.push("d");
alert(asdf.indexOf("d")+"It has been pushed to the end.");
} else {
alert(asdf.indexOf("d")+"It is still there.");
}
}
</script>
</head>
<body>
<input type="button" onclick="myFunction()" value="Show alert">
</body>
</html>