Get to know MDN better
このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
toString() は Array インスタンスのメソッドで、指定された配列とその要素を表す文字列を返します。
なし。
配列の要素の文字列表現です。
Array オブジェクトは Object の toString メソッドをオーバーライドしています。配列の toString メソッドは内部的に join() を呼び出します。そちらで配列を結合し、配列のすべての要素をカンマで区切って一つの文字列に収めて返します。 join メソッドが利用できないか関数ではなかった場合、代わりに Object.prototype.toString が使用され、 [object Array] を返します。
配列を文字列値として表す必要がある場合や、配列が文字列の結合として参照されるとき、 JavaScript は toString メソッドを自動的に呼び出します。
Array.prototype.toString は他の配列も含めて、再帰的にそれぞれの要素を文字列に変換します。Array.prototype.toString` が返す文字列には区切り文字がないので、入れ子配列は平坦化されたように見えます。
配列が循環している(コンテナーそのものである要素を格納している)場合、ブラウザーは循環参照を無視することで無限の再帰を避けます。
join() の動作に従い、 toString() は空のスロットを undefined と同じように扱い、余分な区切り文字を生成します:
toString() は汎用的です。このメソッドは this が join() メソッドを持っていることを期待します。ない場合は、代わりに Object.prototype.toString() を使用します。
| ECMAScript® 2027 Language Specification # sec-array.prototype.tostring |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 2025年8月9日 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.