String.prototype.toString()
toString() メソッドは指定されたオブジェクトを表す文字列を返します。
試してみましょう
構文
str.toString()
返値
呼び出したオブジェクトを表す文字列です。
詳細
その String オブジェクトは、Object の toString メソッドを上書きします。つまり、Object.prototype.toString() を継承しません。String オブジェクトの toString() メソッドは、そのオブジェクトを表す文字列を返します( String.prototype.valueOf() と同等です)。
例
toString メソッドを使う
以下の例は、String オブジェクトを表す文字列の値を表示します。
js
var x = new String('Hello world');
alert(x.toString()) // 'Hello world' を表示します
仕様
| Specification |
|---|
| ECMAScript Language Specification # sec-string.prototype.tostring |
ブラウザー実装状況
BCD tables only load in the browser