Question: Assuming:
str value = 'This is some text';

I want to count how many 't' occurrences, how to do that?

Answer: 
It is much easier with regex

```
var regex = new RegExp("t", "gi")
var count = "This is some text".match(regex).length;

```

Will give you counts of `t` in the given string(ignore case).

You can test it [here](http://jsfiddle.net/arunpjohny/WB7jD/).

Further reference  

[RegExp 1](http://www.w3schools.com/jsref/jsref_obj_regexp.asp)  

[RegExp 2](http://www.regular-expressions.info/javascript.html)  

[String](http://www.w3schools.com/jsref/jsref_obj_string.asp)  

[String.match()](http://www.w3schools.com/jsref/jsref_match.asp)
May be can help you here

```
.replace().length

```

with regards

**Wazzy**