Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何删除Javascript中随机得到的结果_Javascript - Fatal编程技术网

如何删除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