title: derive array of unique property values from an array of objects
body: <p>So, I've got an array of link objects from d3</p>
  
  <pre><code>nodelinks
  (6) […]
  0: Object { index: 1, source: {…}, target: {…} }
  1: Object { index: 5, source: {…}, target: {…} }
  2: Object { index: 8, source: {…}, target: {…} }
  3: Object { index: 9, source: {…}, target: {…} }
  4: Object { index: 10, source: {…}, target: {…} }
  5: Object { index: 21, source: {…}, target: {…} }
  length: 6
  &lt;prototype&gt;: Array []
  </code></pre>
  
  <p>And I want to derive a new array from it containing unique nodes, both <code>source</code> and <code>target</code>. I mangaged to do it like this:</p>
  
  <pre><code>_nodes = []
  nodelinks.forEach(x =&gt; {
    if (!(x.target in _nodes)){_nodes.push(x.target)};
    if (!(x.source in _nodes)){_nodes.push(x.source)};
  });
  
  new Set(_nodes).forEach(x =&gt; d3.select(`#${x.id}`).classed('active', true))
  </code></pre>
  
  <p>But really! There must be a better way: some clever javascripty idiom with <code>map()</code> or <code>filter()</code> or something, yes? Or maybe d3 has some native array method? In python I'd have used a list comprehension. I must be missing something obvious.</p>
  
  <p>any hints?</p>