I have the following Json object -
"links": [
{
"source":"1",
"target":"2"
},
{
"source":"3",
"target":"4"
},
{
"source":"5",
"target":"6"
},
{
"source":"1",
"target":"2"
}
]
How can I remove a link if it already exists e.g. in the aforementioned Json -
{
"source":"1",
"target":"2"
}
Exists twice so in this instance remove the duplicate where source and target match another link exactly.
I have tried -
var temp = [];
$.each(data.links, function (index, value) {
if ($.inArray(value, temp) === -1) {
temp.push(value);
}
});
However temp
ends up with the same amount of links as previous?