What is the best way to trim() in javascript

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

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

19条回答
  •  温柔的废话
    2020-11-29 07:00

    according to this page the best all-around approach is

    return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
    

    Of course if you are using jQuery , it will provide you with an optimized trim method.

提交回复
热议问题