我试图按当月过滤我的对象数组。以动物穿越鱼为例
const fishData = {
"fish_name": "Barreleye",
"price": "15,000",
"location": "Sea",
"shadow_size": "Small",
"n_March": true,
"n_3": true,
},
{
"fish_name": "Coelacanth",
"price": "15,000",
"location": "Sea (Rainy Days)",
"shadow_size": "Largest",
"n_3": true,
}
]
var today = new Date();
var currentMonth = today.getMonth();
var fishMonth = `n_ + ${currentMonth}`;
console.log(fishMonth);
var filteredFish = fishData.filter(function(i) {
return i.fishMonth == true;
});
现在返回,如果我放"n_3"而不是"fishMonth"代码运行良好。我已经检查过了"fishMonth",它确实返回了n_3。什么会阻止这个工作?
牧羊人nacy
30秒到达战场
相关分类