title: How to merge an array with an object where values are arrays
body: <p>I have an array of values and an object where the values are smaller arrays:</p>
  
  <pre><code>array = [1, 2, 3, 4, 2]
  object = {
   gender: [male, female],
   grade:  [7th, 8th, 9th],
  }
  </code></pre>
  
  <p>I want to zip the array and the object so that the values in the array are assigned to the new objects that are keyed with the values in the object, like this:</p>
  
  <pre><code>targetObject = {
    gender: [
      male: 1,
      female: 2,
    ],
    grade: [
      7th: 3,
      8th: 4,
      9th: 2,
    ],
  }
  </code></pre>
  
  <p>My first stab is to iterate through the object and create a new array</p>
  
  <pre><code>var newArray = [];
  for(key in object) {
    for(i=0;i&lt;key.length;i++){
      newArray.push(key[i]);
    }
  }
  </code></pre>
  
  <p>Then zip them together</p>
  
  <pre><code>var newObject = {};
  for (var i = 0; i &lt; newArray.length; i++) {
    newObject[newArray[i]] = array[i];
  }
  </code></pre>
  
  <p>If my syntax is write I believe I'm here:</p>
  
  <pre><code>array == [1, 2, 3, 4, 2]
  object == {
   gender: [male, female],
   grade:  [7th, 8th, 9th],
  }
  newArray == [male, female, 7th, 8th, 9th]
  newObject == {
    male: 1,
    female: 2,
    7th: 3,
    8th: 4,
    9th: 2,
  }
  </code></pre>
  
  <p>It looks like I'm close, but I also feel like I'm stringing together a bunch of fragile code. Is there a better way? And if not, how do I go from my newObject to my targetObject</p>