搜索具有异构类型的对象阵列的过滤器.是角度9的投掷误差



我想搜索一个具有键值对的对象数组。但它在控制台中抛出错误,如图所示:core.js:5873错误类型错误:obj[key].includes不是函数

a = [
{
id: 0,
name: "xyz",
grade: "x",
frade: [
{ name: "Paul", country: "Canada" },
{ name: "Lea", country: "Italy" },
{ name: "John", country: "Italy" }
]
},
{
id: 1,
name: "yaya",
grade: "x"
},
{
id: 2,
name: "x",
frade: "d"
},
{
id: 3,
name: "a",
grade: "b"
}];
filterIt(arr, searchKey) {
return arr.filter(function(obj) {
return Object.keys(obj).some(function(key) {
return obj[key].includes(searchKey);
});
});
}
searchCharacter(res: any) {  // is keyup event in html
console.log(this.filterIt(this.a, 'b'));
}

您可以转换字符串中的object[key]:

String(obj[key]).includes

最新更新