title: Convert an array of IDs to a map object
body: <p>I'm looking for a concise way of creating an object whose property names match values from an array, where all properties have the same value (e.g. <code>true</code>). As an example:</p>
  
  <p>My ID array looks like these arbitrary (in the actual software, not necessarily unique and not necessarily numeric, but primitive) values:</p>
  
  <pre><code>var ids = [4, 15, 8, 16, 42, 23];
  </code></pre>
  
  <p>I am looking for some simple call to convert this into the following object:</p>
  
  <pre><code>{ 4: true, 15: true, 8: true, 16: true, 42: true, 23: true }
  </code></pre>
  
  <p>With JavaScript objects internally being hashmaps, such an object should be much more convenient for quickly checking whether a given ID is contained in the array.</p>
  
  <hr>
  
  <p>Now, <em>of course</em> I know how to generate this object. It's a four-liner:</p>
  
  <pre><code>var idMap = {};
  ids.forEach(function (v) {
      idMap[v] = true;
  });
  </code></pre>
  
  <p>As this pattern occurs over and over in my code (lots of different item IDs being handled in this application), I feel the percentage of "boilerplate" in this is still too large. Furthermore, it appears to me that the four-liner occasionally distracts from the actually tricky algorithms for doing something with various of these ID lists. Therefore, I am looking for a shorter way to write this, hoping that there is something <strong>built-in</strong> either to standard JavaScript or to lodash, which is already in use in our application.</p>
  
  <p>The most related question I could find appears to be <a href="https://stackoverflow.com/questions/35489849/lodash-mapping-array-to-object"><em>lodash: mapping array to object</em></a>. Yet, its proposed solutions are not really shorter and more legible than the above, basically replacing one sort of boilerplate code with another sort (as in my case, I'd usually throw away what the suggested solutions use as values for the object properties and always use <code>true</code> or some similarly small truthy value).</p>
  
  <p>Is there something built-in that allows for a very simple command like</p>
  
  <pre><code>var idMap = arrayToMap(ids);
  </code></pre>
  
  <p>or</p>
  
  <pre><code>var idMap = arrayToMap(ids, true);
  </code></pre>
  
  <p>whose actual name I have not yet found?</p>
  
  <p>(<em>Obviously, the fallback solution is to simply write such a function in our application. I'd prefer to stick as closely as possible with the existing functions, though, hence this question.</em>)</p>