There's unfortunately no join
operator or equivalent in Javascript -- you have to explicitly search for the matches. In your case, you can do this with a nested loop. The code would look something like this.
var results = [];
for(var i = 0; i < statedataset.length; i++) {
if(statedataset[i].State == "SD" ||
statedataset[i].State == "MN" ||
statedataset[i].State == "IA") {
var j = 0;
for(j = 0; j < nationaldataset.length; j++) {
if(nationaldataset[j].nanswer == statedataset[i].columnname) {
break;
}
}
if(j < nationaldataset.length) {
results.push({
"nquestion": nationaldataset[j].nquestion,
"nanswer": nationaldataset[j].nanswer,
"nscore": nationaldataset[j].nscore,
"Score": statedataset[i].Score
});
}
}
}
This should give you a data structure that you can use with D3. And yes, there's almost certainly a nicer way of doing this.