I need to count the number of occurrences of a character in a string.
For example, suppose my string contains:
var mainStr = \"str1,str2,str3,str4\";
Easiest way i found out...
Example-
str = 'mississippi'; function find_occurences(str, char_to_count){ return str.split(char_to_count).length - 1; } find_occurences(str, 'i') //outputs 4