How can i remove duplicated arrays in this data structure?
[![enter image description here][1]][1]
I got this:
JavaScript
x
10
10
1
["5", "26", 300],
2
["7", "10", 20],
3
["3", "4", 30],
4
["5", "2", 52],
5
["9", "5", 300],
6
["3", "4", 30],
7
["5", "2", 52],
8
["5", "26", 300],
9
["1", "27", 250]
10
with:
JavaScript
1
5
1
var all = [].concat(jsonData['l'],jsonData['c'], jsonData['r']);
2
for (e in all){
3
console.log([all[e].source, all[e].target, Number(all[e].link)]);
4
}
5
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. [1]: http://i.stack.imgur.com/1MvXz.png
Advertisement
Answer
You could filter
them:
JavaScript
1
11
11
1
var a = [[1, 2, 3], [1, 2, 3], [4, 5, 6], [4, 5, 6], ['foo']];
2
var tmp = [];
3
4
var b = a.filter(function (v) {
5
if (tmp.indexOf(v.toString()) < 0) {
6
tmp.push(v.toString());
7
return v;
8
}
9
});
10
11
console.log(b);