title: How to use Lodash's unionBy and merge nested arrays?
body: <p>Im looking to merge/combine objects in an array each with a series of nested arrays. I want to merge the objects based on a specific key (here <code>label[1]</code>). I can use Lodash and unionBy to filter out dublicates by <code>label[1]</code>, but how do i keep the values from the filtered items? </p>
  
  <p>The array can look like this:</p>
  
  <pre><code>var arr = [{
      "label": ['item', 'private'],
      "values": [1, 2, 3]
    },
    {
      "label": ['item', 'private'],
      "values": [1, 2, 3, 6]
    },
    {
      "label": ['item', 'work'],
      "values": [1, 2, 8, 9]
    },
    {
      "label": ['item', 'private'],
      "values": [1, 2, 4, 5]
    },
    {
      "label": ['item', 'school'],
      "values": [1, 2, 7]
    }
  ];
  </code></pre>
  
  <p>And the desired output is: </p>
  
  <pre><code>var arr = [{
    "label": ["item", "private"],
    "values": [1, 2, 3, 4, 5, 6 ]
  }, {
    "label": ["item", "work"],
    "values": [1, 2, 8, 9]
  }, {
    "label": ["item", "school"],
    "values": [1, 2, 7]
  }]
  </code></pre>
  
  <p>Here's a sample which is only half way there. </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var arr = [
    { label: ['item','private'], values: [1,2,3] },
    { label: ['item','private'], values: [1,2,3,6] },
    { label: ['item','work'], values: [1,2,8,9] },
    { label: ['item','private'], values: [1,2,4,5] },
    { label: ['item','school'], values: [1,2,7] }
  ];
  
  var result = _.unionBy(arr, "label[1]");
  
  console.log(result);</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.js"&gt;&lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Any ideas? </p>
  
  <p>Thanks
  Lasse</p>