What is the best way to trim() in javascript

前端 未结 19 1963
眼角桃花
眼角桃花 2020-11-29 06:32

The question says it all; JS doesn\'t seem to have a native trim() method.

19条回答
  •  感动是毒
    2020-11-29 06:45

    I use this.

        String.prototype.trim = function() {
            return this.replace(/^\s+|\s+$/g,"");
        }
    

提交回复
热议问题