JSFiddle - React, Tailwind, and code Playground
by Prathameshsb
JavaScript
function search(data, searchTerm) {
const results = [];
for (const entry of data) {
// Convert both the author and title to lowercase for case-insensitive search
const author = entry.author.toLowerCase();
const title = entry.title.toLowerCase();
// Check if either the author or title contains the search term
if (author.includes(searchTerm) || title.includes(searchTerm)) {
results.push(entry);
}
}
return results;
}
const data = [
{ author: 'John Doe', title: 'Introduction to Algorithms', sessionID: '123' },
{ author: 'prat yai', title: 'hoood to Algorithms', sessionID: '1223' },
{ author: 'anish sign', title: 'Introduction to Algorithms', sessionID: '1123' },
{ author: 'jit ass', title: 'Introduction to Algorithms', sessionID: '1423' },
// ... other data entries
];
const searchTerm = 'int'; // Example search term
const searchResults = search(data, searchTerm.toLowerCase());
console.log(searchResults);