If you just want to "remember" the last result, you can do something like this:
var itemArray= [
{
name: 'Apple'
},
{
name: 'Orange'
},
{
name: 'Banana'
}
];
var itemLength = itemArray.length;
var randomNumber = ""
var oldNumber = 1
function getRandomNumber(){
do{
randomNumber = Math.floor(Math.random() * itemLength) + 0;
}
while(randomNumber === oldNumber)
oldNumber = randomNumber
var randomPick = itemArray[randomNumber];
document.getElementById("item").innerHTML = '<b>' + randomPick.name;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…