Skip to content

Instantly share code, notes, and snippets.

@quangnd
Last active July 24, 2016 08:02
Show Gist options
  • Save quangnd/07b596902b710c1674920a437f469991 to your computer and use it in GitHub Desktop.
Save quangnd/07b596902b710c1674920a437f469991 to your computer and use it in GitHub Desktop.
Find occurrence of character in string JS
var theString = "This is a string.";
console.log(theString.split("i").length - 1);
//Example: Count amount of vowels in string
function amoutVowel(wort){
var vowels = ["a","e","i","o","u","ä","ö","ü","E","O","A","I","U"];
var countVowel = 0;
for(var i = 0; i < vowels.length; i++) {
if (wort.indexOf(vowels[i]) !== -1) {
countVowel += wort.split(vowels[i]).length - 1;
}
}
console.log(countVowel);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment