title: lodash: create groups from array of properties in array of objects
body: <p>I've recently been using lodash and I just love it. So I'm on a quest to learn it better.</p>
  
  <p>For the past two days I've been trying to figure out how to do the following, without much success: considering an array of objects each with an array of objects in a property <code>props</code>...</p>
  
  <pre class="lang-js prettyprint-override"><code>let items = [{
    name: 'first',
    props: [{
      id: 1,
      name: 'one'
    }, {
      id: 2,
      name: 'two'
    }]
  }, {
    name: 'second',
    props: [{
      id: 2,
      name: 'two'
    }]
  }, {
    name: 'third',
    props: [{
      id: 1,
      name: 'one'
    }]
  }];
  </code></pre>
  
  <p>... I'd like to create an array of objects containing each property in <code>props</code> across all items, each having an <code>items</code> property with all items containing that property, like this:</p>
  
  <pre class="lang-js prettyprint-override"><code>[{
    id: 1,
    name: 'one',
    items : [] // array containing objects `first` and 'third'
  },{
    id: 2,
    name: 'two',
    items: [] // array containing objects `first` and 'second'
  }]
  </code></pre>
  
  <p>I've tried various combinations inspired from answers of <a href="https://stackoverflow.com/questions/23600897/using-lodash-groupby-how-to-add-your-own-keys-for-grouped-output">this question</a>, which seems the closest I could find to what I'm trying to do.I think my real blocker is that, when trying to create an array of unique props (to which I'm going to map the items) and trying to use...</p>
  
  <pre><code>_(items).chain().flatten().pluck('props').unique().value()
  </code></pre>
  
  <p>... as in <a href="https://stackoverflow.com/a/21557606/1891677">this answer</a>, it tells me <code>.chain(...).flatten(...).pluck</code> is not a function. I also tried with <code>.map</code> instead of <code>.pluck</code>, but I guess not everything working in Underscore works in Lodash (I don't know the specific differences, I just read Lodash was forked from Underscore initially).</p>
  
  <p>Note <strong><em>I know how to do this</em></strong> with classic <code>for</code>s and this is only an exercise. I don't have a practical use for it. </p>
  
  <p>I'm just trying to learn to use <code>lodash</code> to its full potential. If you know how to do it, you don't even have to explain. I'll <code>console.log()</code> each step of the way until I understand what's going on. Also, if you think my question's name could be improved, for better indexing, considering what I want to achieve, I'm open to suggestions.</p>
  
  <p>Ideally, the answer should be a chain of <code>lodash</code> methods, without declaring intermediary variables. I'm pretty sure it's doable (that's why I'm asking). Of course, the fewer steps the better &mdash; I assume it would impact performance in a real life scenario, but this is not a concern here &mdash; I'm aware that most times, when going for performance, the classic <code>for</code> loop is hard to beat.</p>