I am trying to filter to get value by nested data
so if my input is ...

currently I use the code below to get b from maximum a for each name ( christine, smiths, aaron ) . But I am trying to get value b where a = 2 for each name ( christine, hannah, jeannie)
var names = d3.nest()
.key(function(d) { return d.name; })
.entries(data);
names.forEach(function(n) {
n.maxAValue = d3.max(n.values, function(d) { return d.b; });
});
the above works fine, but I was trying to get value where a == 2 with something like this below. Is there a way I could do something like this in javascript ?
names.forEach(function(n) { n.values,
function(d) { if(d.a == 2) { return d.b; } }
});
======Edit======
data = [
{
"name":"apple",
"a":1,
"b":"jame"
},
{
"name":"apple",
"a":2,
"b":"christine"
},
{
"name":"orange",
"a":1,
"b":"nick"
},
{
"name":"orange",
"a":2,
"b":"hannah"
},
{
"name":"orange",
"a":3,
"b":"smiths"
},
{
"name":"peach ",
"a":1,
"b":"boo"
},
{
"name":"peach ",
"a":2,
"b":"jeannie"
},
{
"name":"peach ",
"a":3,
"b":"aaron"
}
]