我想將值推到數組的末尾,但由於某種原因它不工作。當我點擊按鈕時,它應該將值添加到數組的末尾。然後,如果我再次點擊它,它應該告訴我,它仍然存在,但它只是推着陣列。我如何獲得值留在陣列中。推送到數組的值不會保留
<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