I have this array that's returned when a user submits a form:
leaders: [
{
email: '[email protected]',
sites: [
{
name: 'Test',
sitemeta_id: 'xxxxxxxxx',
_checked: true
},
{
name: 'Test 2',
sitemeta_id: 'xxxxxxxx',
_checked: true
}
],
focused: false,
_sitesChecked: 1
},
{
email: '[email protected]',
sites: [
{
name: 'Some Name',
sitemeta_id: 'xxxxx',
_checked: true
},
{
name: 'Names',
sitemeta_id: 'xxxxxxxx'
}
],
focused: false,
_sitesChecked: 2
}
]
I'd like to refactor this to send this array in the specific format the backend is expecting, which would only include site names with the value _checked as true, so the site "Names" wouldn't be included, for example:
leaders: [
{
email: '[email protected]',
sites: ['Test', 'Test2']
},
{
email: '[email protected]',
sites: ['Some Name']
}
]
What's the best way to achieve this in JS (or AngularJS)?