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

JS-like trim method written by myself_javascript skills

WBOY
Release: 2016-05-16 17:20:33
Original
1018 people have browsed it

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*$/, '');
}
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template