Given this json object
{
"contacts": [
{
"name": "Jane doe",
"numbers": [
{
"number": "07123456789"
}
],
"groups": [
{
"group": "Everyone"
},
{
"group": "Exec"
}
]
},
{
"name": "John Smith",
"numbers": [
{
"number": "07987654321"
}
],
"groups": [
{
"group": "Everyone"
}
]
}
]
}
How do I return a new array of telephone numbers where the group equals a given value.
So, for example, I'd expect a single array of "07123456789" where the contact group = "Exec"
Also, where the Group = "Everyone" i'd expect an array of 2 items: "07123456789" and "07987654321"
I've tried:
var data = require('../data/data.json')
var peopleInGroup = data.contacts.filter(function (value) {
value.groups.filter(function (type) {
return type.group === recipients[i];
})
});
recipients is an array of groups "Everyone, "Exec", "Overseas"