刪除的元素可能重複:
How to remove first element of an array in javascript?從陣列中的Javascript
function write() {
for (var x = 1; x <= 3; x++) {
var question = new Array("If you are goofy which is your leading foot", "Riding switch is when you do what", "On your toe side which way should you lean", "question 4", "question 5", "question 6");
var l = question.length;
var rnd = Math.floor(l * Math.random());
document.write(question[rnd]);
document.write("<br>")
}
}
這是我的代碼,但它輸出相同的問題(字符串)有時當我想要的三個問題是不一致的,在輸出後如何從數組中移除一個元素?
如果您是編寫長行代碼的忠實粉絲,您甚至可以將隨機數生成移動到拼接函數第一個參數的位置。 – 2011-05-03 16:13:30