1//get random value from array
2var colors = ["red","blue","green","yellow"];
3var randColor = colors[Math.floor(Math.random() * colors.length)];
4
1//This example is to generate an array with 40 random elements, with random values from 0 to 39
2
3for (var a=[],i=0;i<40;++i) a[i]=i;
4
5// http://stackoverflow.com/questions/962802#962890
6function shuffle(array) {
7 var tmp, current, top = array.length;
8 if(top) while(--top) {
9 current = Math.floor(Math.random() * (top + 1));
10 tmp = array[current];
11 array[current] = array[top];
12 array[top] = tmp;
13 }
14 return array;
15}
16
17a = shuffle(a);
18
1let numbersArray = [] , max = 100;
2
3for( var i=1; numbersArray.push(i++) < max;); // numbers = [1,2,3 ... 100]