How can I make a random array with no repeats?

前端 未结 6 1968
星月不相逢
星月不相逢 2020-12-20 04:13

I\'ve been searching around for some answers to this issue, but nothing seems to work when I try to find a solution.

What I\'m trying to achieve is to make a spinner

6条回答
  •  再見小時候
    2020-12-20 04:21

        var array = [];
    
        setInterval(function(){
    
            if(array .length === 0){ 
                reload(); 
            }
    
            var result = getRandom();
    
            console.log(result);
    
        },1000);
    
        function getRandom(){
            var index = (array.length === 1 ? 0 : Math.floor(Math.random() * array.length));
            return array.splice(index, 1)[0];
        }
    
        function reload(){
            array = [2,3,4,5,6,7,8,9,0,1,44,66];
        }
    

提交回复
热议问题