lundi 3 juin 2019

Random commas appear in array ReactJS

I am trying to create this memory game in ReactJS and I have made an array in which I add 4 random numbers. Now everytime I press play game I need to fill the array with 4 random numbers 0 to 3 but I keep getting random commas that come out of nowhere in the array. I am quite new to React so any help is appreciated.

I have tried different methods of filling up the array but the commas still appear. Ps. keepArray was initialized just before the for loop.

for (let i = 0; i < 4; i++) {
      let rand = Math.floor(Math.random() * 4)
      keepArray = [...keepArray + rand]
      console.log(keepArray)
    }

Screenshot of run: http://prntscr.com/nx9sqg




Aucun commentaire:

Enregistrer un commentaire