I have a JSON Object that looks like this:
{
'name': 'Bob',
'friends': [
{
'name' : 'Ashley (Family)'
},
{
'name' : 'Steven (Non-Family)'
},
{
'name' : 'Chris (Family)'
}
]
}
How can I filter the above, so that it returns only the friends that are family? i.e. friends who's name contains '(Family)'?
function filterFriends (friends) {
return friends.filter(function(i) {
if (i.name.indexOf('(Family)') > -1) {
return i.name;
}
});
}
But the above doesn't seem to work... I don't know if I'm on the right track?
return i.namewithreturn true