I have a simple array, I want to make a search functionality
on this array. I have an input where I enter data to search. But the search goes through all the lines of the object, and I need only lines name
and day
.
How can the code below be modified to implement this functionality, do you have a better option for this?
const data =[
{
name: 'name',
day: 'monday',
year: '2023',
user:'user13421'
},
{
name: 'name1',
day: 'monday1',
year: '20231',
user:'user134211'
}
]
let filtered;
const onSearchF = (keyword) => {
filtered = data.filter((entry) =>
Object.values(entry).some(
(val) =>
typeof val === "string" &&
val.toLowerCase().includes(keyword.toLowerCase())
)
);
};