String.prototype.trim() - 両端の空白文字(white space)を取り除く
String.prototype.trim()は、元の文字列の両端の空白文字(white space)を取り除いた新しい文字列を取得するメソッドです。空白文字は、タブ文字や改行を含みます。
概要
説明
String.prototype.trim ( )
元の文字列の両端の空白文字(white space)を取り除いた文字列を返す。
デモ
String.prototype.trim()のデモです。
<!-- このコードは編集できます。 -->
<!DOCTYPE html>
<html>
<head>
<style>
body {
white-space: pre-wrap ;
}
</style>
</head>
<body>
<script>
/** try it! **/
var string = " SYNCER "
var a = string.trim() ;
/** try it! **/
var results = { a:a, } ;
for( var name in results ) {
console.log( name, results[name] ) ;
document.body.appendChild( new Text( name + " = " + JSON.stringify( results[name] ) + "\n" ) ) ;
}
</script>
</body>
</html>
サポート状況
Chrome | Firefox | Safari | Edge | IE | Opera | iOS Safari | Android |
---|---|---|---|---|---|---|---|
● | ● | ● 5.1+ | ● | ● 9+ | ● | ● | ● |
関連記事
- 要素の位置座標を取得する
- 指定した要素の位置座標を取得します。
- String.prototype.concat()
- String.prototype.concat()は、元の文字と引数に指定した文字を連結して新しい文字列を取得するメソッドです。
- String.prototype.replace()
- String.prototype.replace()は、文字列を置換するメソッドです。置換前の文字は文字列、または正規表現(RegExp)で指定できます。
- String.prototype.charAt()
- String.prototype.charAt()は、指定した位置にある1文字を取得するメソッドです。