diff options
| author | julieng <julien.gattelier@gmail.com> | 2021-08-03 08:03:09 +0200 |
|---|---|---|
| committer | SphinxKnight <SphinxKnight@users.noreply.github.com> | 2021-09-03 08:08:25 +0200 |
| commit | 844f5103992238c0c23203286dad16a466e89c97 (patch) | |
| tree | d537708951bb2b61be8192ffacc05a0ce6804f89 /files/fr/web/javascript/reference/global_objects/string/repeat/index.md | |
| parent | a70fd5b73ecb10bec3906640023e2a1a46e118a2 (diff) | |
| download | translated-content-844f5103992238c0c23203286dad16a466e89c97.tar.gz translated-content-844f5103992238c0c23203286dad16a466e89c97.tar.bz2 translated-content-844f5103992238c0c23203286dad16a466e89c97.zip | |
move *.html to *.md
Diffstat (limited to 'files/fr/web/javascript/reference/global_objects/string/repeat/index.md')
| -rw-r--r-- | files/fr/web/javascript/reference/global_objects/string/repeat/index.md | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/files/fr/web/javascript/reference/global_objects/string/repeat/index.md b/files/fr/web/javascript/reference/global_objects/string/repeat/index.md new file mode 100644 index 0000000000..77600fdf96 --- /dev/null +++ b/files/fr/web/javascript/reference/global_objects/string/repeat/index.md @@ -0,0 +1,84 @@ +--- +title: String.prototype.repeat() +slug: Web/JavaScript/Reference/Global_Objects/String/repeat +tags: + - ECMAScript 2015 + - JavaScript + - Méthode + - Prototype + - Reference + - String + - polyfill +translation_of: Web/JavaScript/Reference/Global_Objects/String/repeat +original_slug: Web/JavaScript/Reference/Objets_globaux/String/repeat +--- +<div>{{JSRef}}</div> + +<p>La méthode <code><strong>repeat()</strong></code> construit et renvoie une nouvelle chaine de caractères qui contient le nombre de copie demandée de la chaine de caractères sur laquelle la méthode a été appelée, concaténées les unes aux autres.</p> + +<div>{{EmbedInteractiveExample("pages/js/string-repeat.html")}}</div> + +<h2 id="Syntaxe">Syntaxe</h2> + +<pre class="syntaxbox"><var>str</var>.repeat(<var>compte</var>)</pre> + +<h3 id="Paramètres">Paramètres</h3> + +<dl> + <dt><code>compte</code></dt> + <dd>Un nombre entier entre 0 and +∞ : [ 0, +∞[, indiquant le nombre de fois que la chaine de caractères doit être repétée dans la nouvelle chaine de caractères.</dd> +</dl> + +<h3 id="Valeur_de_retour">Valeur de retour</h3> + +<p>Une nouvelle chaîne de caractères composée du nombre indiqué de copies de la chaîne appelante.</p> + +<h3 id="Exceptions">Exceptions</h3> + +<ul> + <li>{{jsxref("Erreurs/Negative_repetition_count", "RangeError")}} : le nombre de répétition doit être positif.</li> + <li>{{jsxref("Erreurs/Resulting_string_too_large", "RangeError")}} : le nombre de répétition ne doit pas être infini et la taille de la chaîne résultante ne doit pas dépasser la taille maximale pour une chaîne de caractères.</li> +</ul> + +<dl> + <dt>{{jsxref("RangeError")}}</dt> + <dd>La compteur doit être positif et inférieur à l'infini.</dd> +</dl> + +<h2 id="Exemples">Exemples</h2> + +<pre class="brush:js">"abc".repeat(-1) // RangeError +"abc".repeat(0) // "" +"abc".repeat(1) // "abc" +"abc".repeat(2) // "abcabc" +"abc".repeat(3.5) // "abcabcabc" (le compteur est converti en un nombre entier) +"abc".repeat(1/0) // RangeError + +({toString : () => "abc", repeat : String.prototype.repeat}).repeat(2) +// "abcabc" (repeat() est une méthode générique)</pre> + +<h2 id="Spécifications">Spécifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Spécification</th> + <th scope="col">État</th> + <th scope="col">Commentaire</th> + </tr> + <tr> + <td>{{SpecName('ES2015', '#sec-string.prototype.repeat', 'String.prototype.repeat')}}</td> + <td>{{Spec2('ES2015')}}</td> + <td>Première définition.</td> + </tr> + <tr> + <td>{{SpecName('ESDraft', '#sec-string.prototype.repeat', 'String.prototype.repeat')}}</td> + <td>{{Spec2('ESDraft')}}</td> + <td></td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilité_des_navigateurs">Compatibilité des navigateurs</h2> + +<p>{{Compat("javascript.builtins.String.repeat")}}</p> |
