mardi 14 mars 2017

Select only specific arrays randomly in JavaScript

I have multiple arrays like

 array1 = ["car","boot","bike"];
 array2 = ["table","human","cat"];
 array3 = ["boot","pc","iphone"];
 array4 = ["boot","pc","iphone"];
 array5 = ["bike","human","pet"];

and this is the code to get randomly a array

  var card;
  var rand;
  var arr = [1,2,3,4,5];
  rand = arr[Math.floor(Math.random() * arr.length)];

 if(rand == 1){ card = array1; }else 
 if(rand == 2){ card = array2; }else 
 if(rand == 3){ card = array3; }else 
 if(rand == 4){ card = array4; }else 
 if(rand == 5){ card = array5; }

How can I select from only the arrays without a value "bike" or how can I select from only the arrays without "bike" in the 3rd place in a array?




Aucun commentaire:

Enregistrer un commentaire