I am seeking a solution in Angular.js to verify if duplicate key values exist within a JSON array. Below is a breakdown of my code:
var result=[{
"email":'<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ec8dac8b818d8580c28f8381">[email protected]</a>',
"title":'hello',
"start":'yes'
},{
"email":'<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e485a48389858d88ca878b89">[email protected]</a>',
"title":'hello',
"start":'yes'
},{
"email":'<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bbd9fbdcd6dad2d795d8d4d6">[email protected]</a>',
"title":'ggggg',
"start":'No'
},{
"email":'<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fb9cbb9c969a9297d5989496">[email protected]</a>',
"title":'hel',
"start":'No'
},{
"email":'<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="94f6d4f3f9f5fdf8baf7fbf9">[email protected]</a>',
"title":'ggggg',
"start":'No'
}];
if (result.length > 0) {
angular.forEach(result,function(obj2){
var data={'title':obj2.mname,'start':obj2.date};
evtArr.push(data);
})
}
In this scenario, I need to ensure that before adding new data to evtArr
, it checks for duplicates based on the key - email
. If a value set belonging to a specific email (
<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c6afe8a3eba786a1aba7afaae8a5a9ab">[email protected]</a>
) is already present in evtArr
, then the other one should be removed.