--- title: Array.prototype.toString() slug: Web/JavaScript/Reference/Global_Objects/Array/toString tags: - Array - JavaScript - Method - Prototype translation_of: Web/JavaScript/Reference/Global_Objects/Array/toString --- <div>{{JSRef}}</div> <p><code><strong>toString()</strong></code> メソッドは、指定された配列とその要素を表す文字列を返します。</p> <div>{{EmbedInteractiveExample("pages/js/array-tostring.html","shorter")}}</div> <h2 id="Syntax" name="Syntax">構文</h2> <pre class="syntaxbox notranslate"><var>arr</var>.toString()</pre> <h3 id="Return_value" name="Return_value">返値</h3> <p>配列の要素を表す文字列です。</p> <h2 id="Description" name="Description">解説</h2> <p>{{jsxref("Array")}} オブジェクトは {{jsxref("Object")}} の <code>toString</code> メソッドを上書きしています。Array オブジェクトでは、<code>toString</code> メソッドは配列をつないで、配列のそれぞれの要素がカンマで区切られた 1 つの文字列を返します。</p> <p>配列が文字列値として表される必要がある場合や、配列が文字列の結合として参照される時、JavaScript は <code>toString</code> メソッドを自動的に呼び出します。</p> <h3 id="ECMAScript_5_semantics" name="ECMAScript_5_semantics">ECMAScript 5 でのセマンティック</h3> <p>JavaScript 1.8.5 (Firefox 4)以降、および ECMAScript 第 5 版では、<code>toString()</code> メソッドは一般化されており、すべてのオブジェクトで使用可能となっています。{{jsxref("Object.prototype.toString()")}} が呼び出され、その結果の値が返されます。</p> <h2 id="Examples" name="Examples">例</h2> <h3 id="Using_toString" name="Using_toString">toString を使用する</h3> <pre class="brush: js notranslate">const array1 = [1, 2, 'a', '1a']; console.log(array1.toString()); // expected output: "1,2,a,1a" </pre> <h2 id="Specifications" name="Specifications">仕様書</h2> <table class="standard-table"> <thead> <tr> <th scope="col">仕様書</th> </tr> </thead> <tbody> <tr> <td>{{SpecName('ESDraft', '#sec-array.prototype.tostring', 'Array.prototype.toString')}}</td> </tr> </tbody> </table> <h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> <div> <p>{{Compat("javascript.builtins.Array.toString")}}</p> </div> <h2 id="See_also" name="See_also">関連情報</h2> <ul> <li>{{jsxref("Array.prototype.join()")}}</li> <li>{{jsxref("Object.prototype.toSource()")}}</li> </ul>