0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[JavaScript] 文字列の両端の空白を削除する

Posted at

#概要
インポートしているCSVの文字列に空白文字があり、取り除きたかった時の方法をメモします。

#実装
trim()を使うだけで両端の空白を削除できます。

.js
let hoge = ' hogehoge ';
console.log(hoge.trim());

 //結果:'hogehoge'

先頭文字だけ取り除きたい場合はtrimStart()で可能です。

.js
let hoge = ' hogehoge ';
console.log(hoge.trimStart());

 //結果:'hogehoge '

最後文字はtrimEnd()

.js
let hoge = ' hogehoge ';
console.log(hoge.trimEnd());

 //結果:' hogehoge'
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?