如何基于公共值(在javascript中)合并2个tsv文件

如何基于公共值(在javascript中)合并2个tsv文件,javascript,d3.js,tsv,Javascript,D3.js,Tsv,我有两个tsv文件(tec00104.tsv和tec00114.tsv),其中包含有关国家的信息。我想用两个tsv文件中的公共国家/地区制作一个数组。以及随之而来的价值观。这似乎不起作用,为什么 // initialize array var countries = []; for(var i = 0; i < "tec00114.tsv".length; i++) { for(var j = 0; j < "tec00104.tsv".length; j++) {

我有两个tsv文件(tec00104.tsv和tec00114.tsv),其中包含有关国家的信息。我想用两个tsv文件中的公共国家/地区制作一个数组。以及随之而来的价值观。这似乎不起作用,为什么

// initialize array  
var countries = [];
for(var i = 0; i < "tec00114.tsv".length; i++)
{
for(var j = 0; j < "tec00104.tsv".length; j++)

    {
    // if the country code is found in both tsv files
        if("tec00114.tsv"[i][2] === "tec00104.tsv"[j][3]);
        {
        // append new value to the array
            countries.push("tec00114.tsv"[i]);
            countries.push("tec00104.tsv"[j]);
        }
    }
 }
console.log(countries);
//初始化数组
var国家=[];
对于(变量i=0;i<“tec00114.tsv”。长度;i++)
{
对于(变量j=0;j<“TEC0104.tsv”。长度;j++)
{
//如果在两个tsv文件中都找到了国家代码
如果(“tec00114.tsv”[i][2]=“tec00104.tsv”[j][3]);
{
//将新值追加到数组中
国家推动(“tec00114.tsv”[i]);
国家推动(“tec00104.tsv”[j]);
}
}
}
控制台日志(国家);

问题在于,您试图直接从JavaScript将文件名作为数组引用。这是不可能的。您需要在加载之前加载它们(例如,您可以使用$.get()函数进行加载)

或者你可以用图书馆来做


仅仅引用文件名作为字符串不会导致文件被访问;JavaScript认为您只是在谈论字符串本身?
<script src="alasql.min.js"></script>
<script>
    var countries = alasql('SELECT t1.*, t2.* FROM TSV("tec00114.tsv") t1 \
        JOIN TSV("tec00104.tsv") t2 ON t1.[2] = t2.[3]'); 
</script>
SELECT * FROM TSV("tex00114.tsv", {headers:true});