我有一个多维数组:
var array = [
{
"day":"May 23 2019",
"items": [
{
"Id":1,
"Country":"NL",
"User": 12345
}, {
"Id":2,
"Country":"RU",
"User": 67890
}
]
},
{
"day":"May 20 2019",
"items": [
{
"Id":1,
"Country":"NL",
"User": 222222
}, {
"Id":2,
"Country":"RU",
"User": 333333
}
]
}
]
通过lodash我想过滤用户67890
_.filter(array, { items: [ { User: 67890 } ]});
它会将整个顶级对象返回给我
{
"day":"May 23 2019",
"items": [
{
"Id":1,
"Country":"NL",
"User": 12345
}, {
"Id":2,
"Country":"RU",
"User": 67890
}
]
}
并且我希望它返回(也就是说,“额外”用户不会落入其中,因此最终数组包含具有所需 ID 的严格用户)
{
"day":"May 23 2019",
"items": [ {
"Id":2,
"Country":"RU",
"User": 67890
}
]
},