【发布时间】:2019-10-08 11:43:35
【问题描述】:
我想根据另一个数组过滤具有数组属性的对象数组:
[
{
id: 50,
name: 'test1',
countries: ['RO','GB'],
}, {
id: 51,
name: 'test2',
countries: ['DE', 'RO'],
}, {
id: 52,
name: 'test3',
countries: ['DE'],
}
]
我想返回一个对象数组,可以按国家/地区数组过滤,这意味着如果我想按 1、2 个国家/地区过滤。
1. countries: ['RO']
或
2. countries: ['RO', 'DE'],
预期的输出是:
1.
[
{
id: 50,
name: 'test1',
countries: ['RO', 'DE' ,'GB'],
}, {
id: 51,
name: 'test2',
countries: ['DE', 'RO'],
}
]
2.
[
{
id: 50,
name: 'test1',
countries: ['RO', 'DE' ,'GB'],
}, {
id: 51,
name: 'test2',
countries: ['DE', 'RO'],
}, {
id: 52,
name: 'test3',
countries: ['DE'],
}
]
【问题讨论】:
标签: javascript vue.js