Accepted answer

Use each on the source and target variables to get every value that they return instead of just the first value.

var targets = d3.selectAll("" + d.key);
var sources = d3.selectAll("" + d.key);
var imports = [];
var exports = [];
targets.each(function(d) {
sources.each(function(d) {
console.log("Imports - " + imports);
console.log("Exports - " + exports);

Here is a JSFiddle showing it in action. I added the above code to the mouseover function since that is where the highlighting is done.

D3 methods like attr and style use each behind the scenes so you don't have to, but since you are using a custom function to access data you will need to use each.

Related Query

More Query from same tag