Convert strConflictedYesReviewers data into a single object which is grouped by ownerid first and then groupby opportunityid which contains array of response. I get a dynamic string(strConflictedYesReviewers) which contains multiple user recordswhere each record is separated by semicolon and then each record represents ownerid and opportunityid separated by asterisk. const strConflictedYesReviewers = "88639280*198719943;88642547*198721749;88627345*198721749;88664734*198721749;88686221*198721749;88676217*198721749;88664734*198721749;88686221*198721749;88676217*198721749;" .split(";") .map(item => item.split("*")) .filter(item => !!item[0]) .map(item => ({ownerid: item[0], opportunityid: item[1]})) .reduce(function(acc, curr) { (acc[curr["ownerid"]] = acc[curr["ownerid"]] || []).push(curr["opportunityid"]); return acc; }, {}); console.log(strConflictedYesReviewers); //need the object like the foloowing in the end. { "68642547": { "222": [ "Yes" ] }, "88627345": { "111": [ "No", "Yes", "No" ], "222": [ "Yes" ] }, "88642547": { "111": [ "Yes", "No" ], "222": [ "Yes", "No" ] } }
Hey, I apologise, I made a mistake. I copied the incorrect strConflictedYesReviewers at the top. The correct one is the following: 68642547*222*Yes;88627345*111*No;88627345*111*Yes;88627345*111*No;88627345*222*Yes;88642547*111*Yes;88642547*111*No;88642547*222*Yes;88642547*222*No;
Question is not clear Asifa. Please provide clarity on input and output you desire without js code. input: ....................... output: ......................