I’ve got this snippet of code
const name = 'test1'
const payload = [
{
"manSegChildId": "5497",
"manSegChildDesc": "test4"
},
{
"manSegChildId": "5314",
"manSegChildDesc": "test1"
},
{
"manSegChildId": "5159",
"manSegChildDesc": "test5"
}
]
const newObj = payload.map(nameObj => {
if(nameObj.manSegChildDesc === name) {
return {
"id": nameObj.manSegChildId,
"label" : nameObj.manSegChildDesc,
"disabled": true
}
}
});
console.log(newObj)
I need simply an object I’m returning and not an array and not this undefined ones. Also, is there any optimal way so perform this changes
expected O/P
{
"id": 5314,
"label" : "test1",
"disabled": true
}