const arr = [
{
"id": "753311",
"role": "System Of Record (SOR)",
"license": "Target",
"DC": "Client · L2 (Inactive), Account · L1",
"managedGeography": "North America · L2, International · L2",
"managedSegment": "Institutional Clients Group [L3], Discontinued Ops [L2]",
"checked": true,
"checkBoxPatched": true
},
{
"id": "752872",
"role": "Authorized Redistributor (AR)",
"license": "Interim",
"DC": "Holding · L1, Document · L1, Compliance · L1",
"managedGeography": "Unspecified",
"managedSegment": "Unspecified",
"checked": true,
"checkBoxPatched": true
},
{
"id": "752583",
"role": "Authorized Redistributor (AR)",
"license": "Target",
"DC": "Agreement · L1, Asset · L1, Activity · L1, Account · L1",
"managedGeography": "Unspecified",
"managedSegment": "Unspecified"
}
]
let adsList = arr.map(selectedObj => {
if (selectedObj.checked) {
return selectedObj.role + ", " + selectedObj.license + ", " + selectedObj.DC + ", " + selectedObj.managedGeography + ", " + selectedObj.managedSegment + ";\n"
} else {
return '';
}
}).filter((str) => str.length !== 0).join('\n');
console.log(adsList)
Greetings, I have an array that I'm filtering to return strings only if the object contains a checked property and separating them with a semicolon. However, I am unsure how to remove the last semicolon after unspecified
from the output in this scenario. Any advice on this matter would be greatly appreciated.