I have 2 arrays.
const finalArr = []
const arr = ["abc","def"]
const arr2 = [
{ name: "abc", refresh: false },
{ name: "efd", refresh: false },
{ name: "def", refresh: false }
]
Now I am trying to update the value of refresh to true from arr2 for the name matches from arr, It returns duplicate values:
Here is my code:
arr2.map(obj => {
arr.map(name => {
if (obj.name === name){
finalArr.push({ ...obj, refresh: true })
} else{
finalArr.push({ ...obj, refresh: false })
}
})
Can anybody tell me what is wrong with it?