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)
```
var sValue = 'This is some text';
var tCount = sValue.split("t").length - 1;
alert("t appears " + tCount + " times");

```

If you want to count occurrences of all letters, you better use one loop as shown in the other answers.