I have an object array with duplicate key / value pairs. In this instance, each system has multiple sources. I would like to manipulate it's structure and add system.Title as an object for a single source so that each source has multiple systems.
How can I do this with .map() or .reduce()?
I have supplied the input and desired output below.
//INPUT
var doctypes = [{
"Source": [{
"Title": "Anchor (WI)"
}, {
"Title": "Lafayette Savings Bank"
}, {
"Title": "United Bancorp"
}, {
"Title": "Old National"
}],
"System": {
"Title": "Nautilus"
},
"Title": "Deposit Documents",
}, {
"Source": [{
"Title": "Founders"
}],
"System": {
"Title": "SharePoint"
},
"Title": "Deposit Documents",
}, {
"Source": [{
"Title": "Anchor (MN)"
}],
"System": {
"Title": "OmniView"
},
"Title": "Deposit Documents",
}, {
"Source": [{
"Title": "Old National"
}, {
"Title": "Anchor (WI)"
}, {
"Title": "Lafayette Savings Bank"
}, {
"Title": "United Bancorp"
}],
"System": {
"Title": "CSS (Aperio)"
},
"Title": "Deposit Documents",
}]
// DESIRED OUTPUT
var doctypes = [{
Source: 'Anchor (MN)',
System: [{
Title: 'OmniView'
}]
}, {
Source: 'Anchor (WI)',
System: [{
Title: 'CSS (Aperio)'
}, {
Title: 'Nautilus'
}]
}, {
Source: 'Founders',
System: [{
Title: 'SharePoint'
}]
}, {
Source: 'Lafayette Savings Bank',
System: [{
Title: 'CSS (Aperio)'
}, {
Title: 'Nautilus'
}]
}, {
Source: 'Old National',
System: [{
Title: 'CSS (Aperio)'
}, {
Title: 'Nautilus'
}]
}, {
Source: 'United Bancorp',
System: [{
Title: 'CSS (Aperio)'
}, {
Title: 'Nautilus'
}]
}]
console.log(doctypes)