In need of assistance with selecting specific words from an array. Take for instance this array:
var list = ['Brothers', 'Browsers', 'Dermatologist','Specialist','Optometry']
To perform the selection, I utilize the following script:
var pattern = "Der";
var matched = list.filter(a => a.indexOf(pattern) >= 0);
The matched variable will store:
['Dermatologist']
When changing the value of the pattern variable to "ist", the result would be:
['Dermatologist','Specialist']
Desiring filtering that only matches from the beginning of each word. For example, setting pattern to "Bro" should return:
['Brothers','Browsers']
If the pattern is set to "ers", then the result should be an empty array:
[]
Seeking assistance on achieving this functionality. Can anybody help?