从另一个数组,JavaScript中删除数组的重复 [英] Remove duplicates of array from another array, JavaScript

查看:197
本文介绍了从另一个数组,JavaScript中删除数组的重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在此数据结构中删除重复的数组?

How can i remove duplicated arrays in this data structure?

我得到这个:

    ["5", "26", 300],
    ["7", "10", 20],
    ["3", "4", 30],
    ["5", "2", 52],
    ["9", "5", 300],
    ["3", "4", 30],
    ["5", "2", 52],
    ["5", "26", 300],
    ["1", "27", 250]

with:

var all = [].concat(jsonData['l'],jsonData['c'], jsonData['r']);                                    
for (e in all){
    console.log([all[e].source, all[e].target, Number(all[e].link)]);
}



我需要减少数据,删除重复的数组,并提供结果给sankey graf。 jsonData元素包含更多的数据和每个左边的中心和右边的结构有点不同。



已解决:
我已经建立了我自己的功能在mmm的想法。

I need to reduce data, remove duplicated arrays and provide result to sankey graf. jsonData elements contain much more data and structure of each left, center and right side is a little bit diffrent.

Resolved: I have build my own function based on mmm idea.

function dedupe(all) {
   var seen = [];
   var res = [];
   for (e in all){
       var temp = [all[e].source, all[e].target, Number(all[e].link)];
       if (seen.indexOf(temp.toString()) < 0) {
           seen.push(temp.toString());
           res.push(temp);
       }
   }
   return res;
}

Thans。

推荐答案

你可以过滤器他们:

var a = [[1, 2, 3], [1, 2, 3], [4, 5, 6], [4, 5, 6], ['foo']];
var tmp = [];

var b = a.filter(function (v) {
    if (tmp.indexOf(v.toString()) < 0) {
        tmp.push(v.toString());
        return v;
    }
});

console.log(b);

这篇关于从另一个数组,JavaScript中删除数组的重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆