I have two arrays, "calls" and "Othercalls" with some contact details. Now I wanted to compare these two arrays and update the "status" property to false in "calls" array. The status value should only change in contact those are in "Othercalls" array.
What I tried here is,
These are my two arrays.
this.state = {
calls: [
{
fullname: 'Mark Doe',
phoneNumber: '0112234567',
status: true
},
{
fullname: 'Clark Man',
phoneNumber: '0723434567',
status: true
},
{
fullname: 'Jaden Boor',
phoneNumber: '0778902356',
status: true
},
{
fullname: 'Srick Tree',
phoneNumber: '0980234589',
status: true
},
{
fullname: 'John Doe',
phoneNumber: '0112255644',
status: true
},
{
fullname: 'Mark Doe',
phoneNumber: '0723567890',
status: true
},
{
fullname: 'John Doe',
phoneNumber: '0778904321',
status: true
},
{
fullname: 'Mark Doe',
phoneNumber: '0785674334',
status: true
},
{
fullname: 'Jaden Boor',
phoneNumber: '0713456980',
status: true
},
{
fullname: 'Mark Doe',
phoneNumber: '0112357654',
status: true
},
],
Othercalls: [
{fullname: 'Mark Doe', phoneNumber: '0112234567'},
{fullname: 'Clark Man', phoneNumber: '0723434567'},
{fullname: 'Jaden Boor', phoneNumber: '0778902356'},
]
};
And here I got the details of "othercalls" array and change the status into false. But this is not what I want. I need to compare these two arrays and update the status value to false only in contacts that are in "othercalls" array. And also I need the full data of "calls" array.
let tempList = this.state.Othercalls.map(item => item.phoneNumber);
let result = this.state.calls.filter(item => (tempList.includes(item.phoneNumber)))
result.map((listItem, index) => {
listItem.status = false
})
I want this solution to solve my problem here: (How to compare two array in react native?)