删除Javascript 2D数组中的重复项

时间:2013-03-14 06:03:31

标签: javascript

我已经将第一列排序为2D Javascript数组

var arr = [[12.485019620906078, 236.90974767017053|166.7059999999991|244.15878139435978|156.54100000000025], 
[12.735148445872, 238.038907254076|203.3000000000006|245.7107245706185|213.46500000000034], 
[47.15778769718685, 238.038907254076|203.3000000000006|244.15878139435978|156.54100000000025], 
[47.580051233708595, 236.90974767017053|166.7059999999991|245.7107245706185|213.46500000000034]
];

我试图根据数组[i] [1]部分中的最后两个值删除重复项

244.15878139435978|156.54100000000025
245.7107245706185|213.46500000000034

使用未提供正确输出的跟随功能

function remDupes(arr)
{
    for(var i=0; i<arr.length-1; i++)
    {
        var i1 = arr[i][1].split("|");

        var item1 = i1[2]+"|"+i1[3];

        for(var j=i+1; j<arr.length; j++)
        {
            var i2 = arr[j][1].split("|");

            var item2 = i2[2]+"|"+i2[3];
            if(item1 == item2)
            {
                arr.splice(j,1);
            }
        }
    }
return arr;
}

我正在寻找像这样的最终阵列。

[
[12.485019620906078, 236.90974767017053|166.7059999999991|244.15878139435978|156.54100000000025], 
[12.735148445872, 238.038907254076|203.3000000000006|245.7107245706185|213.46500000000034]
]

0 个答案:

没有答案