私は以下のような2つのjavascript配列オブジェクトを持っています
最初の配列:
count_array[0].left= 0;
count_array[0].width= 33;
count_array[0].id= 1;
count_array[1].left= "";
count_array[1].width= "";
count_array[1].id= 2;
count_array[2].left= "";
count_array[2].width= "";
count_array[2].id= 3;
2番目の配列:
temp_array[0].left= "";
temp_array[0].width= "";
temp_array[0].id= 4;
temp_array[1].left= "";
temp_array[1].width= "";
temp_array[1].id= 5;
temp_array[2].left= 0;
temp_array[2].width= 33;
temp_array[2].id= 1;
以下のような2つの配列からjavascriptでidの一意の値を持つ配列を取得したい
3番目の配列:
temp_array_cnt[0].left= 0;
temp_array_cnt[0].width= 33;
temp_array_cnt[0].id= 1;
以下のコードを使用していますが、機能していません
function intersection(x,y){
x.sort();y.sort();
var i=j=0;ret=[];
while(i<x.length && j<y.length){
if(x[i]<y[j])i++;
else if(y[j]<x[i])j++;
else {
ret.push(x[i]);
i++,j++;
}
}
return ret;
}
ここで私を助けてください。ありがとう
現在、以下の機能を使用しています
function intersection(x,y){
ret=[];
//x.sort();y.sort();
for(var i=0;i<x.length;i++)
{
for(var j=0;j<y.length;i++)
{
//console.log(x[i].eventid);
var chk_left=x[i];
if(chk_left.id == chk_left.id)
{
ret.push(chk_left);
}
}
}
return ret;
}
しかし、この「idがnullであるか、オブジェクトではない」というエラーが発生します。