Javascript String right(count)

Description

Javascript String right(count)



String.prototype.right = function(count) {
    var result = "";

    var stringLength = this.length;

    if (count >= stringLength || count < 0) {
        return String(this);
    }/*ww  w.jav a 2s.  c  o  m*/

    var startIndex = stringLength - count;

    var i;
    for (i = stringLength - 1; i >= startIndex; i -= 1) {
        result = this[i] + result;
    }

    return result;
};



PreviousNext

Related