1

Hi i want to remove duplicate records from attribute in js lightning. component.get("v.recordLeads"); I suppose we have to use lodash function here. Something like this

<aura:attribute name="recordLeads" type="Lead[]" />

var con=component.get("v.convertLeads");    
var result=  _.uniq(con);

1 Answer 1

4

You should be able to avoid underscore.js / lodash if you do something like this:

var uniqueObjs = {};

//create a object with unique leads
con.forEach(function(conItem){
  uniqueObjs[conItem.Id] = conItem;
});
//reinitialise con array
con = [];
var keys = Object.keys(uniqueObjs);

//fill up con again
keys.forEach(function(key){
  con.push(uniqueObjs[key]);
});

If some of your leads are new and don't have ids, you can sometimes make a key out of a combo of fname + lname + email (uppercased or lowercased of course)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .