我对React和Javascript环境还比较陌生,一些语法和错误对我来说不太清晰。我尝试使用filter函数,类似于这样的方式,但是会出现undefined is not an object的错误。
const temp = example.filter(x => x.includes('A'))
例子:
data = [{id: 1, type: Pizza}, {id: 2, type: Taco}, {id: 3, type: Pasta}, {id: 4, type: Sandwich}, {id: 5, type: Pumpkin Pie}]
输出:
temp = [{id: 1, type: Pizza}, {id: 3, type: Pasta}, {id: 5, type: Pumpkin Pie}]