I have a search field which filters through an array when I'm typing. So far it works ok, but I cannot search within the "courses" array! How can I achieve this? The complete array looks like this:
const data = [{
name: "john doe",
city: "blabla",
zipcode: "1234",
email: "[email protected]",
phone: "12345678",
courses: [
{
title: "some course",
provider: "some provider",
end_date: "some date"
},
{
title: "another course",
provider: "another provider",
end_date: "another date"
},
]
]
Here is my JS code so far, where I can search through all fields, except the "courses"-array:
data = data.filter(row => {
return Object.keys(row).some(key => {
return (
String(row[key])
.toLowerCase()
.indexOf(filter) > -1
);
});
});
Can someone help me out?
data.filter(row => JSON.stringify(row).indexOf(filter) > -1)JSON.stringify(), and then remove"...":parts (the field names) using some regular expression from the result.