- 已关闭**。此问题需要details or clarity。当前不接受答案。
- 想要改进此问题?**添加详细信息并通过editing this post阐明问题。
2天前关闭。
Improve this question
我有两个数组arr1是:
数组1 =[{img:"/shoe1.webp ",颜色:"蓝色",价格:950,按钮:“添加到购物车”,名称:"男式运动鞋蓝",尺码:"10 "},{img:"/shoe2.webp ",颜色:"红色",价格:850,按钮:“添加到购物车”,名称:"男式运动鞋红色",尺码:"10 "},{img:"/shoe3.webp ",颜色:"黄色",价格:700,按钮:“添加到购物车”,名称:"男式运动鞋黄色",尺码:"10 "},{img:"/shoe1.webp ",颜色:"蓝色",价格:600,按钮:“添加到购物车”,名称:"男式运动鞋蓝",尺码:"9 "},{img:"/shoe2.webp ",颜色:"红色",价格:550,按钮:“添加到购物车”,名称:"男式运动鞋红色",尺码:"9 "},{img:"/shoe3.webp ",颜色:"黄色",价格:500,按钮:“添加到购物车”,名称:"男式运动鞋黄色",尺码:"9 "},{img:"/shoe1.webp ",颜色:"蓝色",价格:400,按钮:“添加到购物车”,名称:"男式运动鞋蓝",尺码:"8 "},{img:"/shoe2.webp ",颜色:"红色",价格:350,btn:"添加到购物车",名称:"男式运动鞋红色",尺码:"8 "},{img:"/shoe3.webp ",颜色:"黄色",价格:300,按钮:“添加到购物车”,名称:"男式运动鞋黄色",尺码:"8 "},{img:"/shoe1.webp ",颜色:"蓝色",价格:280,按钮:“添加到购物车”,名称:"男式运动鞋蓝",尺码:"7 "},{img:"/shoe2.webp ",颜色:"红色",价格:250,按钮:“添加到购物车”,名称:"男式运动鞋红色",尺码:"7 "},{img:"/shoe3.webp ",颜色:"黄色",价格:200,按钮:“添加到购物车”,名称:"男式运动鞋黄色",尺码:"7 "},{img:"/shoe1.webp ",颜色:"蓝色",价格:170,按钮:“添加到购物车”,名称:"男式运动鞋蓝",尺码:"6 "},{img:"/shoe2.webp ",颜色:"红色",价格:150,按钮:“添加到购物车”,名称:"男式运动鞋红色",尺码:"6 "},{img:"/shoe3.webp ",颜色:"黄色",价格:120,btn:"添加到购物车",名称:"男式运动鞋黄色",尺码:"6 "}
]第二个数组为:
数组2 =["6","7"]
我想用数组2过滤数组1
我想要这个结果
结果=[
{
img: "/shoe1.webp",
color: "blue",
price: 170,
btn: "Add to Cart",
name: "Men Sneaker Blue",
size: "6"
},
{
img: "/shoe2.webp",
color: "red",
price: 150,
btn: "Add to Cart",
name: "Men Sneaker Red",
size: "6"
},
{
img: "/shoe3.webp",
color: "yellow",
price:120,
btn: "Add to Cart",
name: "Men Sneaker Yellow",
size: "6"
},
{
img: "/shoe1.webp",
color: "blue",
price: 280,
btn: "Add to Cart",
name: "Men Sneaker Blue",
size: "7"
},
{
img: "/shoe2.webp",
color: "red",
price: 250,
btn: "Add to Cart",
name: "Men Sneaker Red",
size: "7"
},
{
img: "/shoe3.webp",
color: "yellow",
price: 200,
btn: "Add to Cart",
name: "Men Sneaker Yellow",
size: "7"
}
]
how do i get this result in react functional component
2条答案
按热度按时间ej83mcc01#
您可以将
Array#filter
与Array#includes
结合使用。4uqofj5v2#