I have an array of strings ["samantha", "mike", "john", "sammy", "carla"] and an input value of s.
const input = "s";
let names = ["samantha", "mike", "john", "sammy", "carla"];
let filteredNames = names.filter(name => name.startsWith(input));
This gives me "samantha" and "sammy" as a result.
How can I extract the string that all elements of filteredNames start with? So basically: How can I find out that sam is the matching string for this array?
filteredNames? e.g.["hat","hats","ham"]->ha?