var temp = "This is a string.";
alert(temp.count("is")); // output '2'
I'm looking for a function that counts how many strings in a particular string into a parameter when I insert a string like this, but is there a function like that in JavaScript?
javascript regex string
You can do it simply by writing a regular expression.
var temp = "This is a string.";
var count = (temp.match(/is/g) || []).length;
alert(count);
© 2024 OneMinuteCode. All rights reserved.