I am trying to generate two JSON arrays based on a shared property value from comparing two sets of JSON data.
this.linkedParticipants =[
{
"id": 3,
"name": "Participant 2",
"email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="80f0e1f2f4e9e3e9f0e1eef4b2c0e6e9e3efaee3efed">[email protected]</a>"
},
{
"id": 2,
"name": "Participant 1",
"email"": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f2829380869b919b82939c86c3b2949b919ddc919d9f">[email protected]</a>"
},
{
"id": 1,
"name": "Libin Varghese",
"email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d599bcb7bcbb83b4a7b2bdb0a6b095b3bcb6bafbb6bab8"><email protected></a>"
},
{
"id": 7,
"name": "Participant 5",
"email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b9c9d8cbcdd0dad0c9d8d7cd8cf9dfd0dad697dad6d4"><email protected></a>"
}
]
this.appointmentList = [
{
"id": 32,
"participant": {
"id": 1,
"name": "Libin Varghese",
"email": "<a href="mailto: [email protected]><email protected></a>"
}
},
{
"id": 33,
"participant": {
"id": 7,
"name": "Participant 5",
"email": "<a href="mailto: [email protected]><email protected></a>"
}
}
]
this.invitedList = [];
this.confirmedList = [];
let temp = {}
this.linkedParticipants.forEach((participant, i) => {
this.appointmentList.forEach((appointment, j) => {
if (appointment.participant.name.indexOf(participant.name)) {
temp = {
'participant': participant
}
this.invitedList.push(temp);
}
else {
this.confirmedList.push(appointment)
}
})
})
However, I am encountering an issue where the code is producing duplicate values in the invited list. It seems like there might be some problem with my comparison condition.