Javascript Strings. check for number of strings in strings?

i was wondering how to see how many times a string contains a set of characers. though there might be easy way to do it with javascript. here is what i came up with. it works but it seems silly to say all this.

var checkarray:String[];

 var words:String;
 words="boring fun boring fun boring boring boring";
 
 checkarray = words.Split("fun"[0]);
 
 print("my user had fun " +checkarray.Length-1+" many times");

Also wondering about the String.Contains function.
is there any way to get the character position when using String.Contains?
or the characters following the spot without splitting?

Javascript here.

Are you familiar with Regular Expressions?

You could create a Regular Expression which would match the word “boring,” then you use Javascript’s RegEx functionality to count the number of matches within your string.