I want to select some words out of an array of words. For example, the array is like below:
var list = ['Brothers', 'Browsers', 'Dermatologist','Specialist','Optometry']
I use below script to perform selection
var pattern = "Der";
var matched = list.filter(a => a.indexOf(pattern) >= 0);
The matched variable will contains:
['Dermatologist']
But when I change the pattern variable value to "ist" the result would be
['Dermatologist','Specialist']
I want my filtering to works only matching from the beginning of every word. So if I set pattern variable value to "Bro" it will returns
['Brothers','Browsers']
But when I set pattern variable value to "ers" it will returns empty array
[]
Can anybody help?