数组如下var arr = [ {id: "1", en: "Afghanistan", cn: "阿富汗", code: "93"}, {id: "2", en: "Iraq", cn: "伊拉克", code: "964"}, {id: "3", en: "Qatar", cn: "卡塔尔", code: "974"} ]en,cn,code都能查询比如输入aq,查询返回第二条比如输入卡,查询返回第三条比如输入97,查询返回第三条
1 回答
犯罪嫌疑人X
TA贡献2080条经验 获得超4个赞
function query(arr, q) {
return arr.filter(v => Object.values(v).some(v => new RegExp(q + '').test(v))
)
}
添加回答
举报
0/150
提交
取消