+ 4
Well, you can use this function getRandomInt(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; } var data = ["Data1","Aditya","random","Value"]; setInterval(function(){ document.write(data[getRandomInt(0,3)]); },1000); getRandomInt give you random integer between, 0 to 3. You can change it to your min and max index number of array.
30th Nov 2016, 2:36 PM
Aditya kumar pandey
Aditya kumar pandey - avatar
+ 3
You can use it. do not need to give credit. But thanks that you like it.
1st Dec 2016, 1:59 PM
Aditya kumar pandey
Aditya kumar pandey - avatar
0
multiply the result of Math.random() with size of your array ex: size = 10; random number is a decimal number from 0 to 1 if 10*random number, and get the floor of the result, you have a random number between 0 and 10 that is an random index of your array to make ensurance that you'll don't any error of indexes, you can return the result of remainder random index dividing by 10(size)
30th Nov 2016, 2:29 PM
Nima Moradi
Nima Moradi - avatar