Modern JavaScript Web Development Cookbook
上QQ阅读APP看书,第一时间看更新

Trimming strings

You may trim a string at both ends, or only at one, by using .trim(...), .trimStart(...), and .trimEnd(...):

"   Hello, there!  ".trim();      //    "Hello, there!"
" Hello, there! ".trimStart(); // "Hello, there! "
" Hello, there! ".trimEnd(); // " Hello, there!"
Originally,   .trimStart()  was   .trimLeft(), and   .trimEnd()  was   .trimRight(), but the names were changed for the same reason as   .padStart()  and   .padEnd() were.