In my attempt to filter out emails
that already exist in the userData
, the current issue is that my code continuously adds the same data as long as the email
is not the same.
Below is the code snippet:
userData:[ {email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="791318171c571d161c3914181015571a1614">[email protected]</a>",
first_name: "Jane",
last_name: "Doe"},
{email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1c76737472327873795c6f7d716c7079327f7371">[email protected]</a>",
first_name: "john",
last_name: "doe"},
{email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bcd1ddcec5e3d6ddd2d9fcd1ddd5d092dfd3d1">[email protected]</a>",
first_name: "Mary",
last_name: "Jane"}
],
parseData:[ {email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fa909b949fd49e959fba979b9396d4999597">[email protected]</a>",
first_name: "Jane",
last_name: "Doe"},
{email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3e745156505047617c4c5f48517e4d5f534e525b105d5153">[email protected]</a>",
first_name: "Johnny",
last_name: "Bravo"},
{email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="feb49f878d9190d0bf9c8b9b929fbe939f9792d09d9193">[email protected]</a>",
first_name: "Jayson",
last_name: "Abuela"}
],
newData: []
var userData = this.userData
var parsedData = this.parseData
function(results) {
const parsedData = results.data
for(var j = 0; j < parsedData.length; j++){
userData.map((data)=>{
if(data.email.toLowerCase() != parseData[j].email.toLowerCase()){
newData.push(parsedData[j])
}else{
alert("This "+parsedData[j].email+" already exist.")
}
})
}
}
The expected behavior is to have the user
with email
of
<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="672d080f09091e3825150611082714060a170b024904080a">[email protected]</a>
and <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6a200b13190504442b081f0f060b2a070b030644090507">[email protected]</a>
pushed into my newData only once, but currently each data gets pushed multiple times.