所以,我正在制作一个蒸汽贸易机器人,我需要帮助删除其他物品中的其他人的库存,只显示金属。
例如数组
["Refined Metal", "Refined Metal", "Reclaimed Metal", "Scrap Metal", "Flare Gun", "Strange Shotgun"]
我想让代码去掉其他没有"Metal“一词的字符串。
我尝试过array.filter,但我认为这不是我正在做的事情的正确函数
我试过了
var = ["Refined Metal", "Refined Metal", "Reclaimed Metal", "Scrap Metal", "Flare Gun", "Strange Shotgun"]
var = var(array.filter => "Metal")我不知道怎么用滤镜
我希望它能显示出来:["Refined Metal", "Refined Metal", "Reclaimed Metal", "Scrap Metal"]
发布于 2019-09-07 09:52:09
如果总是大写M,则使用filter和includes
const metals = array.filter(e => e.includes("Metal"));如果是其中一种情况:
const metals = array.filter(e => /metal/i.test(e));https://stackoverflow.com/questions/57830091
复制相似问题