Home >Web Front-end >JS Tutorial >js substring gets the specified length string from the right (sample code)_javascript skills

js substring gets the specified length string from the right (sample code)_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:07:351198browse

如下所示:

复制代码 代码如下:

 /*

   Get the rightmost substring, of the specified length,

   from a String object.

*/ 

String.prototype.right = function (length_) 



        var _from = this.length - length_; 

        if (_from < 0) _from = 0; 

        return this.substring(this.length - length_, this.length); 

}; 
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn