trim() 方法,删除前后空格符

5.3.3 String

6.trim() 方法
ECMAScript在所有字符串上都提供了 trim() 方法。这个方法会创建
字符串的一个副本,删除前、后所有空格符,再返回结果。比如:

let stringValue = " hello world ";
let trimmedStringValue = stringValue.trim();
console.log(stringValue); // " hello world "
console.log(trimmedStringValue); // "hello world"

另外, trimeLeft() 和 trimRight() 方法分别用于从字符串开始
和末尾清理空格符。

原文地址:https://www.cnblogs.com/huanghuali/p/14673134.html