Answers for "Write a code that will print how many times a vowel is present in a particular string and also print the index of where it's found."

0

Write a code that will print how many times a vowel is present in a particular string and also print the index of where it's found.

const text = "This is a simple text";
const pattern = /[aeiou]/g;
let output = "";
while((result = pattern.exec(text)) !== null) {
 output += result[0] + " " + pattern.lastIndex + "\n";
}
console.log(output);

/* output
i 3
i 6
a 9
i 12
e 16
e 19
*/
Posted by: Guest on October-17-2021

Code answers related to "Write a code that will print how many times a vowel is present in a particular string and also print the index of where it's found."

Browse Popular Code Answers by Language