title: Combine arrays of objects by object index
body: <p>I am filtering an array for every value the is the same as the key provided. Im certain there is a one shot reduce method someone better than me can condense this down to, but alas filter map filter map.</p>
  <p>So I submit to an array an object that says <code>[{k:v}, {k2:otherv}]</code> and find all the elements that are not that and then return those object keys.</p>
  <p>The code below returns:</p>
  <pre><code>  [
      {k: v1},
      {k: v2},
      {k: v3}
    ]
     [
      {k2: v4},
      {k2: v5},
      {k2: v6}
     ]
   ]
  </code></pre>
  <p>And obviously to map over it correctly id like it to look like
  <code>[{k:v1, k2:v4}, {k:v2,k2:v5}, {k:v3, k2:v6}]</code></p>
  <p>I've tried several examples from:</p>
  <p><a href="https://stackoverflow.com/questions/43125960/how-can-i-merge-two-object-arrays-by-index-in-javascript">How can I merge two object arrays by index in JavaScript?</a></p>
  <p>and</p>
  <p><a href="https://stackoverflow.com/questions/34076624/combine-same-index-objects-of-two-arrays">Combine same-index objects of two arrays</a></p>
  <p>but short of writing every object key possible into each of these, none of what I've tried works.</p>
  <pre><code>const blogkeys = cont
     .filter((k) =&gt; k.type === &quot;blogs&quot;)
     .map(({ key, content }) =&gt; {
      if (key.includes(&quot;.&quot;)) {
       let objkey = key.substr(key.indexOf(&quot;.&quot;) + 1, key.length);
  
       let obj = { [objkey]: content };
  
       let arrName = key.substr(0, key.indexOf(&quot;.&quot;));
  
       let pushedObj = { [arrName]: [{ ...obj }] };
  
       return pushedObj;
      } else {
       let obj = { [key]: content };
       return obj;
      }
     });
  </code></pre>
  <p>this creates the keys we are looking for in the parent array</p>
  <pre><code>
    const everyOtherBlog = blogkeys.map((blogkey) =&gt; {
     const returned = blogs
      .filter(
       (f) =&gt;
        !JSON.stringify(f).includes(
         JSON.stringify(blogkey).replace(&quot;{&quot;, &quot;&quot;).replace(&quot;}&quot;, &quot;&quot;)
        )
      )
      .map(({ _doc }) =&gt; {
       let obj = {};
  
       Object.keys(_doc)
        .filter((f) =&gt; f === Object.keys(blogkey)[0])
        .map((a) =&gt; {
         obj = Object.assign(obj, { [a]: _doc[a] });
  
         return obj;
        });
  
       return obj[0];
      });
  
     return returned;
    });
  
  </code></pre>
  <p>This returns the data set you see.</p>
  <p>Here is what blogkeys looks like :</p>
  <pre><code>[0] [
  [0]   { title: ' stuff' },
  [0]   {
  [0]     p1: ' stuff '
  [0]   }
  [0] ]
  </code></pre>
  <p>which is made from</p>
  <pre><code>  {
  [0]     _id: '606a4049d4812928986afc10',
  [0]     contentId: '60443ced4e233336f8306b5b',
  [0]     type: 'blogs',
  [0]     key: 'title',
  [0]     content: 'stuff'
  [0]   },
  </code></pre>
  <p>and a blog looks something like</p>
  <pre><code>{
   title: '',
   p1:''
  }
  </code></pre>
  <p>Everyone here provided alot of cool stuff that ended up not helping me because of how i was feeding the data in, when i fixed that i realized i didnt need any fancy zips just good old object.fromEntries. Ill leave this up though cause some of these are very interesting.</p>
  <p>Any help would be great</p>