title: plain javascript - function to get set of pairs from two arrays
body: <p>given two arrays (of unknown size) like so:</p>
  
  <pre><code>var first = ['A1','A2','A3'];
  var second= ['B1','B2'];
  </code></pre>
  
  <p>I want to get set of all possible pairs from those arrays. In above example proper result should look like this:</p>
  
  <pre><code>var result = [['A1B1','A2B2'], ['A1B1','A3B2'],['A1B2','A2B1'],['A1B2','A3B1'],['A2B1','A3B2'],['A2B2','A3B1']];
  </code></pre>
  
  <p>I tried to come up with solution on my own, but I am stuck in increasingly bigger numer of nested loops...</p>
  
  <p>EDIT:</p>
  
  <p>Sorry, perhaps I wasn't that clear when forming my question. Maybe it would be easier on an example - let's assume that first array contains names of truck drivers, and second array contains cities. Each driver can only drive to one city, and each city can only be visited by single driver.</p>
  
  <p>In this scenario expected output of the function would be a complete list of possible combinations (driver + city). Unknown lengths of input arrays obviously means that there may be drivers that won't drive anywhere, and there might be cities which won't get visited by any driver.</p>
  
  <p>I hope now my question is more clear now.</p>
  
  <p>EDIT2:</p>
  
  <p>I don't think this is a duplicate of <a href="https://stackoverflow.com/questions/6058868/finding-all-possible-value-combinations-between-two-arrays">Finding all possible value combinations between two arrays</a> since accepted answer in that question works only (if I understand it correctly) for second array of length 2.</p>