JSFiddle - React, Tailwind, and code Playground

by Pankaj Kargirwar

JavaScript

function findPartialMatches(str, array) {
    // Use the filter method to filter out strings with partial matches
    // Convert both the string and array elements to lowercase for case-insensitive matching
    return array.filter(item => item.toLowerCase().includes(str.toLowerCase()));
}

// Example usage:
let array = ['apple', 'banana', 'orange', 'grape', 'pear', 'strawberry'];
let str = 'an';

let matches = findPartialMatches(str, array);
if (matches.length > 0) {
    console.log("Partial matches found:", matches);
} else {
    console.log("No partial matches found.");
}