score:3

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("path.link.target-" + d.key);
var sources = d3.selectAll("path.link.source-" + d.key);
var imports = [];
var exports = [];
targets.each(function(d) {
  imports.push(d["source"].key);
});
sources.each(function(d) {
  exports.push(d["target"].key);
});
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