我想将值推到数组的末尾,但由于某种原因它不工作。当我点击按钮时,它应该将值添加到数组的末尾。然后,如果我再次点击它,它应该告诉我,它仍然存在,但它只是推着阵列。我如何获得值留在阵列中。推送到数组的值不会保留
<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>
谢谢。我应该抓住那个。 – Brunus