SYNCERのロゴ
アイキャッチ画像

String.prototype.trim() - 両端の空白文字(white space)を取り除く

String.prototype.trim()は、元の文字列の両端の空白文字(white space)を取り除いた新しい文字列を取得するメソッドです。空白文字は、タブ文字や改行を含みます。

概要

名前
trim
所属
String.prototype
仕様書
https://tc39.github.io/ecma262/#sec-string.prototype.trim

説明

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>

サポート状況

ChromeFirefoxSafariEdgeIEOperaiOS SafariAndroid
5.1+ 9+
  • Twitterでシェア
  • Facebookでシェア
  • Google+でシェア
  • はてなブックマークでシェア
  • pocketに保存
  • LINEでシェア
更新履歴
2017年9月29日 (金)
コンテンツを公開しました。