-4

I have three arrays with 2 strings each, and would like to randomly select one of the arrays.

array1 = ["hello", "world"];
array2 = ["all", "good"];
array3 = ["bye", "now"];

Something like collecting the three arrays into one, and then math.random? I'm working with JsPsych, in case it is relevant

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
  • 1
    Add your arrays to another array, then use the answers from [Getting a random value from a JavaScript array](https://stackoverflow.com/q/4550505/215552) – Heretic Monkey Mar 31 '21 at 12:08

1 Answers1

0

To combine arrays with each other, you can use the method contact().

For example :

var test1 = ['Emil', 'Tobias'];
var test2 = ['Arthur', 'Simon'];
var array = test1.concat(test2);

For generate a random value, read this topic : Getting a random value from a JavaScript array

  • Thank you! Still, this is choosing strings form both variables at once eg. I'm getting Emil and Simon – jseabra Mar 31 '21 at 12:36