I have a situation where I need to compare the names and values of two arrays filled with objects.
const array1 = [
{
name: 'Sarah',
value: null
},
{
name: 'Michael',
value: null
}
]
const array2 = [
{
name: 'Sarah',
value: '1'
}
]
If the object's name
property in array2 is found in array1, then update the value of the name to '0', otherwise leave it unchanged.
The desired outcome should be :
[
{
"name": "Sarah",
"value": "0"
},
{
"name": "Michael",
"value": null
]
Could someone please provide guidance on how to achieve this?