There are only two simple ways to learn
The first feature that can be rewritten using the array length
Idea: You can use a for loop to place the number from 0 to 100 in an array, then shuffle the 100 numbers using sort (), and then get 10 different numbers by rewriting the length of the array to 10.
<! DOCTYPE html>varArr=[]; for(vari=0;i<100;i++) {//an array from 0 to 100Arr.push (i); } arr.sort (function(){//randomly scrambling this array returnMath.random ()-0.5; }) Arr.length= 10;//Rewrite lengthConsole.log (arr);//the console will output 10 different numbers</script>The second advantage is the unique character of the JSON object's key value.
Idea: Define an empty array and an empty JSON object to save the array first, respectively.
<! DOCTYPE html>// json object, the key value is unique, the key value can be a number var arr=[]; var json={}; while (Arr.length<10 var k=math.round (math.random () *100 if (! =true ; Arr.push (k); }} console.log (arr) </script>
Randomly remove 10 number of repetitions from 0~100