0

Well basically I have this array with images:

var random_images = ["1.png","2.png","3.png","4.png","5.png","6.png","7.png","8.png","9.png","10.png","11.png","12.png","13.png","14.png","15.png","16.png","17.png","18.png","19.png","20.png","21.png" ];

I want to fill them all [randomly] to another array:

 var myArray = new Array(100)  (as you can see i want to fill those images to 100 spaces and each time i refresh the page i need to scatter them randomly)

I have tried to do it with:

var combinedArray = myArray.concat(random_images);

It doesn't seem to work. Is there any other way to it?

Matías Fidemraizer
  • 63,804
  • 18
  • 124
  • 206
Ralfs R
  • 77
  • 1
  • 8

1 Answers1

1
var newArray = new Array(100);

for (i = 0; i < 100; i++) {
    newArray[i] = random_images[Math.floor(Math.random() * random_images.length)];

You can try a code like this.

jcubic
  • 61,973
  • 54
  • 229
  • 402
LoïcR
  • 4,940
  • 1
  • 34
  • 50