toString

概要

指定された配列とその要素を表す文字列を返します。

Array のメソッド
実装されたバージョン: JavaScript 1.1, NES 2.0
ECMA バージョン: ECMA-262

構文

toString()

パラメータ

なし

JavaScript 1.8.5 note

Starting in JavaScript 1.8.5, and consistent with ECMAScript 5th edition semantics, the toString() method is generic and can be used with any object. If the object has a join() method, it will be called and that value will be returned.  Otherwise Object.prototype.toString() will be called, and the resulting value will be returned.

説明

Array オブジェクトは ObjecttoString メソッドを上書きしています。Array オブジェクトでは、toString メソッドは配列をつないで、配列のそれぞれの要素がコンマで区切られた 1 つの文字列を返します。例えば、以下のコードは配列を生成し、その配列を文字列に変換するために toString を使っています。

var monthNames = new Array("Jan","Feb","Mar","Apr");
myVar = monthNames.toString(); // myVar に "Jan,Feb,Mar,Apr" を代入

配列が文字列値として表されるべきときや、配列が文字列の結合で参照されたとき、JavaScript は toString メソッドを自動的に呼び出します。

参照

toSource

Tags (1)

タグを編集

Attachments (0)

 

添付ファイル