Trying to search through an array of objects using key-value pairs, but encountering an error in the console: core.js:5873 ERROR TypeError: obj[key].includes is not a function
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) { // on keyup event in HTML
console.log(this.filterIt(this.a, 'b'));
}