我想通过另一个数组的项目过滤一个对象数组。这是我的物品清单:
const list = ["first", "second", "third"]
这个数组可以是空的,有一个,两个或三个 itens...例如:
const list = []
const list = ["first"]
let list = ["first", "third"]
所以,我需要使用我的状态list来过滤我myArr2的。
const myArr2 = [
{
id: "1",
language: "portuguese",
status: "first"
},
{
id: "2",
language: "portuguese",
status: "first"
},
{
id: "3",
language: "portuguese",
status: "second"
},
{
id: "4",
language: "portuguese",
status: "third"
},
{
id: "5",
language: "portuguese",
status: "second"
},
]
如果我list的是:
const list = [ "first", "third" ]
输出必须是:
const myArr2 = [
{
id: "1",
language: "portuguese",
status: "first"
},
{
id: "2",
language: "portuguese",
status: "first"
},
{
id: "4",
language: "portuguese",
status: "third"
},
]
如果我list的是:
const list = [ "first" ]
输出必须是:
const myArr2 = [
{
id: "1"
language: "portuguese"
status: "first"
},
{
id: "2"
language: "portuguese"
status: "first"
}
}
等等...
我制作了这段代码但无法正常工作:
Object.entries(list).forEach(status => {
myArr2.filter(item => {
if(item.status === status){
return item
}
})
})
我究竟做错了什么?有人可以帮助我吗?
陪伴而非守候
繁花不似锦
慕姐4208626
相关分类