Because you are not looking for a simple attribute AFAIK you can't use findWhere. Instead you can either use indexBy to get a rearranged collection (good for many similar lookups) or find with a test function (good for occasional lookups):
// http://jsfiddle.net/tshpfz0x/3/
var members = [{
id: 1,
user: {
name: 'John Smith',
email: '[email protected]'
}
}, {
id: 2,
user: {
name: 'Jane Smith',
email: '[email protected]'
}
}];
console.info(_.findWhere(members, {
user: {
email: '[email protected]'
}
})); // undefined
function byEmail(member) {return member.user.email;}
console.info(
_.indexBy(members, byEmail)["[email protected]"]
); // Object
console.info(
_.find(members, function (member) {
return (byEmail(member) === "[email protected]");})
); // Object
{user.email …is a syntax error!