Javascript String right(n)

Description

Javascript String right(n)

String.prototype.right = function(n) {
        return this.substr((this.length-n),this.length);
};

Javascript String right(n)

/**/*  w ww.  ja v a2 s .c o  m*/
 * get a substring of a particular length from the right
 * 
 * @function module:String.prototype.right
 * @param {number}     n     The lenth of the string to return
 * @return {string}
 * @example
 *  'foobar'.right(3) === 'bar'
 */
String.prototype.right = String.prototype.right || function(n) {
 return this.substr((this.length-n),this.length);
};



PreviousNext

Related