如何删除Javascript中随机得到的结果
我需要显示随机文本,但我需要这些不被重复。这是密码,谢谢如何删除Javascript中随机得到的结果,javascript,Javascript,我需要显示随机文本,但我需要这些不被重复。这是密码,谢谢 var textos=new Array() textos[0]=“text1”; textos[1]=“tex2.”; textos[2]=“tex3.”; textos[3]=“tex4”; textos[4]=“text5”; 函数aleatorio(){ document.getElementById(“resultado”).innerHTML=“”; nro=Math.floor(Math.random()*(textos.
var textos=new Array()
textos[0]=“text1”;
textos[1]=“tex2.”;
textos[2]=“tex3.”;
textos[3]=“tex4”;
textos[4]=“text5”;
函数aleatorio(){
document.getElementById(“resultado”).innerHTML=“”;
nro=Math.floor(Math.random()*(textos.length-0)+0);
document.getElementById(“resultado”).innerHTML=textos[nro];
}
sigunte
一种方法可以是:
删除使用的位置,以便下次不再重复。
例如:
var textos=new Array()
textos[0]=“text1”;
textos[1]=“text2”;
textos[2]=“text3”;
textos[3]=“text4”;
textos[4]=“text5”;
函数aleatorio(){
document.getElementById(“resultado”).innerHTML=“”;
如果(textos.length>0){
nro=Math.floor(Math.random()*(textos.length-0)+0);
document.getElementById(“resultado”).innerHTML=textos[nro];
//从数组中删除此索引,使其不会重复
textos.拼接(nro,1);
}否则{
document.getElementById(“resultado”).innerHTML=“全部完成”;
}
}
sigunte