title: D3 - forEach is not a function when upgrading from v3 to v4
body: <p>I am trying to upgrade <a href="http://bl.ocks.org/KatiRG/f7d064cd9c3efbc3c360" rel="noreferrer">this</a> stackable bar chart to v4.
  Everything works except for one thing.</p>
  
  <p>When I filter one category the bars don't drop to the start of the x-axis. I get an error which says:  </p>
  
  <blockquote>
    <p>state.selectAll(...).forEach is not a function</p>
  </blockquote>
  
  <p>I've tried multiple things but I can't figure this one out.
  This is the broken code:</p>
  
  <pre><code>function plotSingle(d) {
  
  class_keep = d.id.split("id").pop();
  idx = legendClassArray.indexOf(class_keep);
  
  //erase all but selected bars by setting opacity to 0
  d3.selectAll(".bars:not(.class" + class_keep + ")")
      .transition()
      .duration(1000)
      .attr("width", 0) // use because svg has no zindex to hide bars so can't select visible bar underneath
      .style("opacity", 0);
  
  //lower the bars to start on x-axis
  state.selectAll("rect").forEach(function(d, i) {
  
      //get height and y posn of base bar and selected bar
      h_keep = d3.select(d[idx]).attr("height");
      y_keep = d3.select(d[idx]).attr("y");
  
      h_base = d3.select(d[0]).attr("height");
      y_base = d3.select(d[0]).attr("y");
  
      h_shift = h_keep - h_base;
      y_new = y_base - h_shift;
  
      //reposition selected bars
      d3.select(d[idx])
          .transition()
          .ease("bounce")
          .duration(1000)
          .delay(750)
          .attr("y", y_new);
  
  })
  }
  </code></pre>
  
  <p>I find it strange that this works flawlessly in D3 v3, why wouldn't this work in v4?</p>