Javascript 具有多个条件的给定json数组的Lodash筛选器

Javascript 具有多个条件的给定json数组的Lodash筛选器,javascript,ecmascript-6,lodash,Javascript,Ecmascript 6,Lodash,我有一个json数组,如下所示,我使用lodash进行过滤 const data = [ { "id": "66b2bc0b-2486-4bb0-a93c-0337ebe1d647", "company_id": "41c56094-ed7e-4fa3-a83e-2e93c6ea5750", "name": null, "type

我有一个json数组,如下所示,我使用lodash进行过滤

const data =  [
    {
      "id": "66b2bc0b-2486-4bb0-a93c-0337ebe1d647",
      "company_id": "41c56094-ed7e-4fa3-a83e-2e93c6ea5750",
      "name": null,
      "type": null,
      "model": null,
      "serial_number": null,
      "mac_address": null,
      "firmware_verison": null,
      "gateway_id": null,
      "device_code": "ST921WF-001E5E02C002",
      "location_id": null,
      "status": null,
      "updated_at": "2020-11-17T07:05:57.037Z",
      "created_at": "2020-11-17T07:05:57.037Z",
      "created_by": null,
      "updated_by": null
    },
    {
      "id": "975c51f8-a6cb-4701-aaa6-077f8a9974a5",
      "company_id": "41c56094-ed7e-4fa3-a83e-2e93c6ea5750",
      "location_id": null,
      "type": null,
      "name": null,
      "model": null,
      "status": null,
      "serial_number": null,
      "mac_address": null,
      "firmware_verison": null,
      "gateway_id": null,
      "device_code": "ST921WF-001E5E02C001",
      "created_by": null,
      "updated_by": null,
      "created_at": "2020-11-17T07:05:57.015Z",
      "updated_at": "2020-11-17T07:05:57.167Z"
    },
    {
      "id": "c4d5e446-c137-443c-a4d7-2c54c204c018",
      "company_id": "fe49fc61-729d-4a68-8cef-1a4041ff739e",
      "name": null,
      "type": null,
      "model": null,
      "serial_number": null,
      "mac_address": null,
      "firmware_verison": null,
      "gateway_id": null,
      "device_code": "ST921TH-001E5E02C001_Naveen",
      "location_id": null,
      "status": "active",
      "updated_at": "2020-11-18T12:10:56.027Z",
      "created_at": "2020-11-18T12:10:56.027Z",
      "created_by": null,
      "updated_by": null
    },
    {
      "id": "9287ce48-e60b-4e8a-96a5-cbedd1ee3be2",
      "company_id": "fe49fc61-729d-4a68-8cef-1a4041ff739e",
      "name": null,
      "type": "smart-plug",
      "model": null,
      "serial_number": null,
      "mac_address": null,
      "firmware_verison": null,
      "gateway_id": null,
      "device_code": "ST921TH-001E5E02C002",
      "location_id": null,
      "status": null,
      "updated_at": "2020-11-18T12:11:21.867Z",
      "created_at": "2020-11-18T12:11:21.867Z",
      "created_by": null,
      "updated_by": null
    },
    {
      "id": "6bf58e90-6a84-480e-b944-2cabb90f60c9",
      "company_id": "fe49fc61-729d-4a68-8cef-1a4041ff739e",
      "name": null,
      "type": "gateway",
      "model": null,
      "serial_number": null,
      "mac_address": null,
      "firmware_verison": null,
      "gateway_id": null,
      "device_code": "ST921GW-001E5E02C002",
      "location_id": null,
      "status": "active",
      "updated_at": "2020-11-18T12:12:23.431Z",
      "created_at": "2020-11-18T12:12:23.431Z",
      "created_by": null,
      "updated_by": null
    }
  ]
我需要根据eg的多个条件过滤数组

从数据中筛选{状态:“活动”,“类型”:“网关”}

它应该返回满足此条件的所有对象。where条件应该是动态的,并且应该接受任何支持的字段进行筛选。我尝试了以下操作,但无法添加多个条件

const filteredData = lodash.find(data, ['status', 'active']);

有没有办法做到这一点?如果有,请帮我提供一个示例代码

用于过滤数据,您可以使用lodash library的
过滤方法。我附上了一段代码片段。希望这有助于解决问题

const数据=[{
“id”:“66b2bc0b-2486-4bb0-a93c-0337ebe1d647”,
“公司id”:“41c56094-ed7e-4fa3-a83e-2e93c6ea5750”,
“名称”:空,
“类型”:空,
“模型”:空,
“序列号”:空,
“mac_地址”:空,
“固件验证”:空,
“网关id”:空,
“设备代码”:“ST921WF-001E5E02C002”,
“位置id”:空,
“状态”:空,
“更新时间”:“2020-11-17T07:05:57.037Z”,
“创建时间”:“2020-11-17T07:05:57.037Z”,
“创建人”:null,
“更新者”:null
},
{
“id”:“975c51f8-a6cb-4701-aaa6-077f8a9974a5”,
“公司id”:“41c56094-ed7e-4fa3-a83e-2e93c6ea5750”,
“位置id”:空,
“类型”:空,
“名称”:空,
“模型”:空,
“状态”:空,
“序列号”:空,
“mac_地址”:空,
“固件验证”:空,
“网关id”:空,
“设备代码”:“ST921WF-001E5E02C001”,
“创建人”:null,
“更新者”:空,
“创建时间”:“2020-11-17T07:05:57.015Z”,
“更新时间:”2020-11-17T07:05:57.167Z
},
{
“id”:“c4d5e446-c137-443c-a4d7-2c54c204c018”,
“公司id”:“fe49fc61-729d-4a68-8cef-1a4041ff739e”,
“名称”:空,
“类型”:空,
“模型”:空,
“序列号”:空,
“mac_地址”:空,
“固件验证”:空,
“网关id”:空,
“设备代码”:“ST921TH-001E5E02C001\U Naveen”,
“位置id”:空,
“状态”:“活动”,
“更新时间”:“2020-11-18T12:10:56.027Z”,
“创建时间”:“2020-11-18T12:10:56.027Z”,
“创建人”:null,
“更新者”:null
},
{
“id”:“9287ce48-e60b-4e8a-96a5-cbedd1ee3be2”,
“公司id”:“fe49fc61-729d-4a68-8cef-1a4041ff739e”,
“名称”:空,
“类型”:“智能插头”,
“模型”:空,
“序列号”:空,
“mac_地址”:空,
“固件验证”:空,
“网关id”:空,
“设备代码”:“ST921TH-001E5E02C002”,
“位置id”:空,
“状态”:空,
“更新时间”:“2020-11-18T12:11:21.867Z”,
“创建时间”:“2020-11-18T12:11:21.867Z”,
“创建人”:null,
“更新者”:null
},
{
“id”:“6bf58e90-6a84-480e-b944-2cabb90f60c9”,
“公司id”:“fe49fc61-729d-4a68-8cef-1a4041ff739e”,
“名称”:空,
“类型”:“网关”,
“模型”:空,
“序列号”:空,
“mac_地址”:空,
“固件验证”:空,
“网关id”:空,
“设备代码”:“ST921GW-001E5E02C002”,
“位置id”:空,
“状态”:“活动”,
“更新时间”:“2020-11-18T12:12:23.431Z”,
“创建时间”:“2020-11-18T12:12:23.431Z”,
“创建人”:null,
“更新者”:null
}
];
常量filteredata=u.filter(数据{
状态:“活动”,
类型:“网关”
})
console.log(filteredData)
lodash.filter(数据,{status:'active',type:'gateway'})
应该可以工作。