pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/repeat

ref="https://developer.mozilla.org/favicon.ico" />

このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

String.prototype.repeat()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年9月.

repeat()String 値のメソッドで、呼び出し元の文字列を指定した数だけコピーして結合した新しい文字列を構築して返します。

試してみましょう

const mood = "Happy! ";

console.log(`I feel ${mood.repeat(3)}`);
// 予想される結果: "I feel Happy! Happy! Happy! "

構文

js
repeat(count)

引数

count

0 から Infinity までの間の整数で、文字列を繰り返す数を示します。

返値

与えられた文字列の指定した回数分のコピーを含む新しい文字列です。

例外

RangeError

count が負の数であるか、 count が文字列の最大長を超えた場合に発生します。

repeat() の使用

js
"abc".repeat(-1); // RangeError
"abc".repeat(0); // ''
"abc".repeat(1); // 'abc'
"abc".repeat(2); // 'abcabc'
"abc".repeat(3.5); // 'abcabcabc' (小数点以下は切り捨てられます)
"abc".repeat(1 / 0); // RangeError

({ toString: () => "abc", repeat: String.prototype.repeat }).repeat(2);
// 'abcabc' (repeat() は汎用メソッドです)

仕様書

Specification
ECMAScript® 2026 Language Specification
# sec-string.prototype.repeat

ブラウザーの互換性

関連情報

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy