I have some array of objects value and I need to check some key value pair and update the objects accordingly using Javascript. I am explaining my code below.\
let arr =[
{
'id': 11,
'name':'Raj',
"code":0
},
{
'id': 11,
'name':'Raj',
'code': 1
},
{
'id':32,
'name':'Krishna',
'code':1
},
{
'id':32,
'name':'fff',
'code':0
},
{
'id':43,
'name':'FAQ',
'code':0
}
]
let arr1 = arr.map((item,i) => {
const found = arr.some(el => el.code === 1);
if(found) {
}
})
Here I have array of objects and I need if any record has code=1 as per id then all record's code=1 belongs to same id. My expected output will be like below.
let arr =[
{
'id': 11,
'name':'Raj',
"code":1
},
{
'id': 11,
'name':'Raj',
'code': 1
},
{
'id':32,
'name':'Krishna',
'code':1
},
{
'id':32,
'name':'fff',
'code':1
},
{
'id':43,
'name':'FAQ',
'code':0
}
]
Here for id=11 there is one record which has code=1 so all records belongs to id=11 the code value will be 1;