ビルトインのString.replace
メソッドを使って空白を''
に置換する
const hoge = ' hoge foo bar '
hoge.replace(/\s/g, '') // => "hogefoobar"
なおtrim
では文字列中の空白は取り除くことができないので注意。
More than 3 years have passed since last update.
ビルトインのString.replace
メソッドを使って空白を''
に置換する
const hoge = ' hoge foo bar '
hoge.replace(/\s/g, '') // => "hogefoobar"
なおtrim
では文字列中の空白は取り除くことができないので注意。
Register as a new user and use Qiita more conveniently