find vowels in a string javascript code example
Example 1: how to make a vowel counter in javascript
function getCount(str) {
let vowelList = 'AEIOUaeiou'
let vowelsCount = 0;
for(var i = 0; i < str.length ; i++)
{
if (vowelList.indexOf(str[i]) !== -1)
{
vowelsCount += 1;
}
}
return vowelsCount;
}
Example 2: count vowels in a string javascript
// BEST and FASTER implementation using regex
const countVowels = (str) => (str.match(/[aeiou]/gi) || []).length