Trim string in JavaScript?

后端 未结 20 2401
不知归路
不知归路 2020-11-21 06:27

How do I trim a string in JavaScript? That is, how do I remove all whitespace from the beginning and the end of the string in JavaScript?

20条回答
  •  南方客
    南方客 (楼主)
    2020-11-21 07:10

    Here's a very simple way:

    function removeSpaces(string){
    return string.split(' ').join('');
    }
    

提交回复
热议问题