Home  >  Article  >  Web Front-end  >  JS-like trim method written by myself_javascript skills

JS-like trim method written by myself_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:20:33990browse

Since the trim method of JS is not supported in many browsers, here we can use the trim method written by ourselves to deal with the need to cut off the empty strings at both ends of the string. There are many processing methods. I only choose one here. Tested by yourself

Copy code The code is as follows:

String.prototype.trim = function () {
return this .replace(/^ss*/, '' ).replace(/ss*$/, '');
}
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