Last active
July 24, 2016 08:02
-
-
Save quangnd/07b596902b710c1674920a437f469991 to your computer and use it in GitHub Desktop.
Find occurrence of character in string JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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