search bar in javascript

index.tsx
const search = (arr, target) => {
    let results = [];
    
    for (let i = 0; i < arr.length; i++) {
        if (arr[i].includes(target)) {
            results.push(arr[i]);
        }
    }
    
    return results;
}

const array = ['apple', 'banana', 'orange', 'grape', 'pear'];
const searchTerm = 'app';

const searchResults = search(array, searchTerm);
console.log(searchResults);
387 chars
18 lines

related categories

gistlibby LogSnag