fill array with random values js code example
Example 1: javascript generate random array
for (var a=[],i=0;i<40;++i) a[i]=i;
function shuffle(array) {
var tmp, current, top = array.length;
if(top) while(--top) {
current = Math.floor(Math.random() * (top + 1));
tmp = array[current];
array[current] = array[top];
array[top] = tmp;
}
return array;
}
a = shuffle(a);
Example 2: generate an array of random numbers javascript
let numbersArray = [] , max = 100;
for( var i=1; numbersArray.push(i++) < max;);