--- title: String.prototype.concat() slug: Web/JavaScript/Reference/Global_Objects/String/concat tags: - JavaScript - Prototype - Reference - String - メソッド translation_of: Web/JavaScript/Reference/Global_Objects/String/concat --- <div>{{JSRef}}</div> <p><span class="seoSummary"><strong><code>concat()</code></strong> メソッドは、文字列引数を呼び出し文字列に連結して、新しい文字列を返します。</span></p> <div>{{EmbedInteractiveExample("pages/js/string-concat.html")}}</div> <div class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力したい場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</div> <h2 id="Syntax" name="Syntax">構文</h2> <pre class="syntaxbox"><var>str</var>.concat(<var>str2</var> [, ...<var>strN</var>])</pre> <h3 id="Parameters" name="Parameters">引数</h3> <dl> <dt><code><var>str2</var> [, ...<var>strN</var>]</code></dt> <dd><code><var>str</var></code> に連結する文字列。</dd> </dl> <h3 id="Return_value" name="Return_value">返値</h3> <p>提供された文字列を結合したテキストを含む新しい文字列。</p> <h2 id="Description" name="Description">解説</h2> <p><code>concat()</code> 関数は、文字列引数を呼び出し文字列に連結し、新しい文字列を返します。元の文字列または返された文字列の変更は、他の文字列には影響しません。</p> <p>引数が文字列型でない場合は、連結前に文字列値に変換されます。</p> <h2 id="Performance" name="Performance">性能</h2> <p><code>concat()</code> メソッドの代わりに {{jsxref("Operators/Assignment_Operators", "代入演算子", "", 1)}} (<code>+</code> または <code>+=</code>) を使用する事を強くお勧めします。<br> この<a href="https://jsperf.com/concat-vs-plus-vs-join">性能試験</a>によれば、{{jsxref("Operators/Assignment_Operators", "代入演算子", "", 1)}}のほうが数倍高速です。</p> <h2 id="Examples" name="Examples">例</h2> <h3 id="Using_concat" name="Using_concat">concat() の使用</h3> <p>複数の文字列を連結してコンソールに表示する例を以下に示します。</p> <pre class="brush: js">let hello = 'こんにちは、' console.log(hello.concat('鈴木さん', '。よい1日を。')) /* こんにちは、鈴木さん。よい1日を。*/ let greetList = ['こんにちは', ' ', '佐藤さん', '!'] "".concat(...greetList) // "こんにちは 佐藤さん!" "".concat({}) // [object Object] "".concat([]) // "" "".concat(null) // "null" "".concat(true) // "true" "".concat(4, 5) // "45" </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-string.prototype.concat', 'String.prototype.concat')}}</td> </tr> </tbody> </table> <h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> <div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> <p>{{Compat("javascript.builtins.String.concat")}}</p> <h2 id="See_also" name="See_also">関連情報</h2> <ul> <li>{{jsxref("Array.prototype.concat()")}}</li> <li>{{jsxref("Operators/Assignment_Operators", "Assignment operators", "", 1)}}</li> </ul>