find vowels in string js code example

Example 1: count vowels in javascript

const vowels = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'];

function countVowels(sentence) {
  let counts = 0;
  for(let i = 0; i < vowels.length; i++) {
    if(vowels.includes(sentence[i])) {
      counts++;
    }
  }
  return console.log(counts);
}

countVowels('Hello World');
countVowels('AaEeIiOoUu');
countVowels('aaaaa');

Example 2: find the vowel js

function vowel_count(str1)
{
  var vowel_list = 'aeiouAEIOU';
  var vcount = 0;
  
  for(var x = 0; x < str1.length ; x++)
  {
    if (vowel_list.indexOf(str1[x]) !== -1)
    {
      vcount += 1;
    }
  
  }
  return vcount;
}
console.log(vowel_count("The quick brown fox"));

Example 3: how to make a vowel counter in javascript

const vowelCount = str => {
  let vowels = /[aeiou]/gi;
  let result = str.match(vowels);
  let count = result.length;

  console.log(count);
};

Example 4: 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;
}