Javascript String countChars()

Description

Javascript String countChars()

String.prototype.countChars = function() {
    var u = {};//from w  w w  . j av  a 2  s. c o  m
    for (var i = 0; i < this.length; i++) {
        if (!u.hasOwnProperty(this[i])) {
            u[this[i]] = 0;
        }
        u[this[i]]++;
    }
    return u;
}



PreviousNext

Related