var list1 =[{user: "A", id: 'a'},
{user: "B", id: 'b'},
{user: "C", id: 'c'},
{user: "D", id: 'd'},
{user: "E", id: 'e'}];
var list2 = ["A","B","C"];
I have above two arrays and i want to filter list1 by using list2. My output should be [{id: 'a'},{id: 'b'},{id: 'c'}] or only ['a','b','c'].
I am doing following way to filter but not getting any result. What is wrong here?
var ids = _.filter(list1, function(id) {
_.each(list2, function(name){
return id.user === name;
});
});