在Javascript/Lodash中过滤对象数组中的多个字段

在Javascript/Lodash中过滤对象数组中的多个字段,javascript,arrays,object,lodash,Javascript,Arrays,Object,Lodash,我有以下数组: 人民主义者 [ {id:1, name:"Brian", status:"active"}, {id:2, name:"Mary", status:"active"}, {id:3, name:"John", status:"pending"}, {id:4, name:"Steph", status:"pending"}, {id:5, name:"Peter", status:"inactive"} ] 状态列表 [ 'active', 'pending'] 我只想

我有以下数组:

人民主义者

[ {id:1, name:"Brian", status:"active"}, {id:2, name:"Mary", status:"active"},
  {id:3, name:"John", status:"pending"}, {id:4, name:"Steph", status:"pending"},
 {id:5, name:"Peter", status:"inactive"}
]
状态列表

[ 'active', 'pending']
我只想将对象数组过滤到statusList,因此我执行了以下操作:

var filteredPeople  =PeopleList.map(person => {
  for (var i=0; i<=statusList.length; i++){
    if(statusList[i] == person.active)
        return {...person};
  }
});

我如何使其在条件未通过时从列表中删除该对象

应该使用
filter
来过滤数组,而不是
map
。您还可以使用
包括

var data=[{id:1,名称:“Brian”,状态:“active”},{id:2,名称:“Mary”,状态:“active”},
{id:3,姓名:“John”,状态:“待定”},{id:4,姓名:“Steph”,状态:“待定”},
{id:5,姓名:“彼得”,状态:“不活动”}
]
var statusList=[“活动”、“挂起”]
var result=data.filter(e=>statusList.includes(e.status))
console.log(结果)
var statusList=[];
变量PeopleList=[
{id:1,名称:“Brian”,状态:“active”},
{id:2,姓名:“玛丽”,状态:“活动”},
{id:3,姓名:“John”,状态:“待定”},
{id:4,姓名:“Steph”,状态:“待定”},
{id:5,姓名:“彼得”,状态:“不活动”}
];
对于(var counter=0;counter”;
}
//这是您的状态数组
console.log(状态列表);
//循环遍历javascript状态数组中的所有元素并将它们打印出来
对于(变量i=0;i”+状态列表[i]+”
); }
   [object, object, object,object, undefined ] 
var statusList = [];

var PeopleList = [

  { id: 1, name: "Brian", status: "active" },
  { id: 2, name: "Mary", status: "active" },
  { id: 3, name: "John", status: "pending" },
  { id: 4, name: "Steph", status: "pending" },
  { id: 5, name: "Peter", status: "inactive" }

];

for (var counter = 0; counter < PeopleList.length; counter++)
{

statusList.push(PeopleList[counter].status);

document.write(PeopleList[counter].status + "<br />");
}

// Here is your Status array
console.log(statusList);

// loop through all elements in your javascript status array and print them out
for (var i = 0; i < statusList.length; i++)
{

    document.write("<strong>" + statusList[i] + "<br />");
}