嗨,我在过滤掉对象数组中的值时遇到问题。所以基本上我有一个对象数组
const arr = [
{
"id": null,
"name": null,
"role": "Authorized Redistributor (AR)",
"checked": false,
"checkBoxPatched": true
},
{
"id": null,
"name": null,
"role": "System Of Record (SOR)",
"checked": true,
"checkBoxPatched": true
},
{
"id": null,
"name": null,
"role": "Authorized Redistributor (AR)",
"checked": true,
"checkBoxPatched": true
}
]
arr.map(res => res.checked ? res.role : "").join(', ')
// ", System Of Record (SOR), Authorized Redistributor (AR)"
如果
role
为真,我需要逗号分隔的checked
值。所以从上面的对象来看,O/P应该是System Of Record (SOR), Authorized Redistributor (AR)
.