D3.js v4 count values in an object

We want to count the number of each value that occurs in an object. In this array of object we want to know how many ‘f’ value and how many ‘m’ values there are on the key ‘gender’.
Great link and more indepth examples on Phoebe Bright‘s page.
Also a running example on github.

var data = [{
        name: "Sarah",
        gender: "f",
        value: 1
      },
      {
        name: "Bob",
        gender: "m",
        value: 2
      },
      {
        name: "Amy",
        gender: "f",
        value: 3
      },
    ]

var data_count = d3.nest()
      .key(function(d) {
        return d.gender;
      })
      // .key(function(d) { return d.priority; })
      .rollup(function(leaves) {
        return leaves.length;
      })
      .entries(data);

    data_count.forEach(function(element) {
      console.log(element);
    });
data_count=[
{key: "f", value: 2},
{key: "m", value: 1}
]