I want to create two JSON array based on a common property value by comparing two JSONs.
this.linkedParticipants =[
{
"id": 3,
"name": "Participant 2",
"email": "participant2@fico.com"
},
{
"id": 2,
"name": "Participant 1",
"email": "participant1@fico.com"
},
{
"id": 1,
"name": "Libin Varghese",
"email": "LibinVarghese@fico.com"
},
{
"id": 7,
"name": "Participant 5",
"email": "participant5@fico.com"
}
]
this.appointmentList = [
{
"id": 32,
"participant": {
"id": 1,
"name": "Libin Varghese",
"email": "LibinVarghese@fico.com"
}
},
{
"id": 33,
"participant": {
"id": 7,
"name": "Participant 5",
"email": "participant5@fico.com"
}
}
]
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)
}
})
})
But the code is not working as expected as the two values this.invitedList is giving out duplicate values. My comparing condition has some issues I think.