JSFiddle - React, Tailwind, and code Playground

by superbDeveloper

JavaScript

//Count the number of occurances of a character in a string in Javascript


var mainStr = "str1,str2,str3,str4";


alert("looking for commas: " + (mainStr.split(",").length - 1) ); //3
    
alert("looking for str: " + (mainStr.split("str").length - 1) ); //4