1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
---
title: String.prototype
slug: conflicting/Web/JavaScript/Reference/Global_Objects/String
tags:
- JavaScript
- Propriété
- Prototype
- Reference
- String
translation_of: Web/JavaScript/Reference/Global_Objects/String
translation_of_original: Web/JavaScript/Reference/Global_Objects/String/prototype
original_slug: Web/JavaScript/Reference/Objets_globaux/String/prototype
---
<div>{{JSRef}}</div>
<p>La propriété <strong><code>String.prototype</code></strong> représente l'objet prototype de {{jsxref("String")}}.</p>
<div>{{js_property_attributes(0,0,0)}}</div>
<h2 id="Description">Description</h2>
<p>Toutes les instances de {{jsxref("String")}} héritent de <code>String.prototype</code>. Les modifications de l'objet prototype <code>String</code> sont répercutées sur toutes les instances de <code>String</code>.</p>
<h2 id="Propriétés">Propriétés</h2>
<dl>
<dt><code>String.prototype.constructor</code></dt>
<dd>Définit la fonction créant le prototype d'un objet.</dd>
<dt>{{jsxref("String.prototype.length")}}</dt>
<dd>Reflète la longueur de la chaîne</dd>
<dt><code><em>N</em></code></dt>
<dd>Utilisée pour accéder au caractère en <em>N</em><sup>ème</sup> position où <em>N</em> est un entier entre 0 et la valeur de {{jsxref("String.length")}} moins un. Ces propriétés sont en lecture seule.</dd>
</dl>
<h2 id="Méthodes">Méthodes</h2>
<h3 id="Méthodes_non_liées_à_HTML">Méthodes non liées à HTML</h3>
<dl>
<dt>{{jsxref("String.prototype.charAt()")}}</dt>
<dd>Renvoie le caractère (ou plus précisement, le point de code UTF-16) à la position spécifiée.</dd>
<dt>{{jsxref("String.prototype.charCodeAt()")}}</dt>
<dd>Renvoie un nombre indiquant la valeur du point de code UTF-16 du caractère à la position spécifiée.</dd>
<dt>{{jsxref("String.prototype.codePointAt()")}}</dt>
<dd>Renvoie un entier positif qui est la valeur du codet UTF-16 à la position donnée.</dd>
<dt>{{jsxref("String.prototype.concat()")}}</dt>
<dd>Combine le texte de deux chaînes et renvoie une nouvelle chaîne.</dd>
<dt>{{jsxref("String.prototype.includes()")}}</dt>
<dd>Défini si une chaîne de caractères est contenue dans une autre chaîne de caractères.</dd>
<dt>{{jsxref("String.prototype.endsWith()")}}</dt>
<dd>Défini si une chaîne de caractère se termine par une chaîne de caractères spécifique.</dd>
<dt>{{jsxref("String.prototype.indexOf()")}}</dt>
<dd>Renvoie la position, au sein de l'objet <code>String</code> appelant, de la première occurrence de la valeur spécifiée, ou -1 si celle-ci n'est pas trouvée.</dd>
<dt>{{jsxref("String.prototype.lastIndexOf()")}}</dt>
<dd>Renvoie la position, au sein de l'objet String appelant, de la dernière occurrence de la valeur spécifiée, ou -1 si celle-ci n'est pas trouvée.</dd>
<dt>{{jsxref("String.prototype.localeCompare()")}}</dt>
<dd>Renvoie un nombre indiquant si une chaîne de référence vient avant, après ou est en position identique à la chaîne donnée selon un ordre de tri.</dd>
<dt>{{jsxref("String.prototype.match()")}}</dt>
<dd>Utilisée pour faire correspondre une expression rationnelle avec une chaîne.</dd>
<dt>{{jsxref("String.prototype.matchAll()")}}</dt>
<dd>Renvoie un itérateur listant l'ensemble des correspondances d'une expression rationnelle avec la chaîne.</dd>
<dt>{{jsxref("String.prototype.normalize()")}}</dt>
<dd>Retourne la forme Unicode normalisée de la chaîne de caractères appelée.</dd>
<dt>{{jsxref("String.prototype.padEnd()")}}</dt>
<dd>Complète la chaîne courante avec une autre chaîne de caractères, éventuellement répétée, afin d'obtenir une nouvelle chaîne de la longueur indiquée. La chaîne complémentaire est ajoutée à la fin.</dd>
<dt>{{jsxref("String.prototype.padStart()")}}</dt>
<dd>Complète la chaîne courante avec une autre chaîne de caractères, éventuellement répétée, afin d'obtenir une nouvelle chaîne de la longueur indiquée. La chaîne complémentaire est ajoutée au début.</dd>
</dl>
<dl>
<dt>{{jsxref("String.prototype.quote()")}} {{obsolete_inline}}</dt>
<dd>Entoure la chaîne de guillemets doubles anglais ("<code>"</code>").</dd>
<dt>{{jsxref("String.prototype.repeat()")}}</dt>
<dd>Renvoie une chaîne dont le contenu est la chaîne courante répétée un certain nombre de fois.</dd>
<dt>{{jsxref("String.prototype.replace()")}}</dt>
<dd>Utilisée pour rechercher une correspondance entre une expression rationnelle et une chaîne, et pour remplacer la sous-chaîne correspondante par une nouvelle chaîne.</dd>
<dt>{{jsxref("String.prototype.search()")}}</dt>
<dd>Exécute la recherche d'une correspondance entre une expression régulière et une chaîne spécifiée.</dd>
<dt>{{jsxref("String.prototype.slice()")}}</dt>
<dd>Extrait une section d'une chaîne et renvoie une nouvelle chaîne.</dd>
<dt>{{jsxref("String.prototype.split()")}}</dt>
<dd>Sépare un objet String en un tableau de chaînes en séparant la chaîne en plusieurs sous-chaînes.</dd>
<dt>{{jsxref("String.prototype.startsWith()")}}</dt>
<dd>Détermine si une chaîne commence avec les caractères d'une autre chaîne.</dd>
<dt>{{jsxref("String.prototype.substr()")}} {{deprecated_inline}}</dt>
<dd>Renvoie les caractères d'une chaîne à partir de la position spécifiée et pour la longueur spécifiée.</dd>
<dt>{{jsxref("String.prototype.substring()")}}</dt>
<dd>Renvoie les caractères d'une chaîne entre deux positions dans celle-ci.</dd>
<dt>{{jsxref("String.prototype.toLocaleLowerCase()")}}</dt>
<dd>Les caractères de la chaîne seront convertis en minuscules selon la locale courante. Pour la plupart des langues, le résultat est identique à {{jsxref("String.prototype.toLowerCase()", "toLowerCase()")}}.</dd>
<dt>{{jsxref("String.prototype.toLocaleUpperCase()")}}</dt>
<dd>Les caractères de la chaîne seront convertis en majuscules selon la locale courante. Pour la plupart des langues, le résultat est identique à {{jsxref("String.toUpperCase()", "toUpperCase()")}}.</dd>
<dt>{{jsxref("String.prototype.toLowerCase()")}}</dt>
<dd>Renvoie la valeur de la chaîne appelante convertie en minuscules.</dd>
<dt>{{jsxref("String.prototype.toSource()")}} {{ Non-standard_inline() }}</dt>
<dd>Renvoie une représentation littérale de l'objet; celle-ci peut être utilisée pour créer un nouvel objet. Remplace la méthode {{jsxref("Object.prototype.toSource()")}}.</dd>
<dt>{{jsxref("String.prototype.toString()")}}</dt>
<dd>Renvoie une chaîne représentant l'objet spécifié. Remplace la méthode {{jsxref("Object.prototype.toString()")}}.</dd>
<dt>{{jsxref("String.prototype.toUpperCase()")}}</dt>
<dd>Renvoie la valeur de la chaîne appelante convertie en majuscules.</dd>
<dt>{{jsxref("String.prototype.trim()")}}</dt>
<dd>Retire les blancs en début et en fin de chaîne. Cette méthode a été définie avec ECMAScript 5.</dd>
<dt>{{jsxref("String.prototype.trimStart()")}}<br>
{{jsxref("String.prototype.trimLeft()")}}</dt>
<dd>Retire les blancs situés au début de la chaîne.</dd>
<dt>{{jsxref("String.prototype.trimEnd()")}}<br>
{{jsxref("String.prototype.trimRight()")}}</dt>
<dd>Retire les blancs situés à la fin de la chaîne.</dd>
<dt>{{jsxref("String.prototype.valueOf()")}}</dt>
<dd>Renvoie la valeur primitive de l'objet spécifié. Remplace la méthode {{jsxref("Object.prototype.valueOf()")}}.</dd>
<dt>{{jsxref("String.prototype.@@iterator()","String.prototype[@@iterator]()")}}</dt>
<dd>Renvoie un nouvel objet <code>Iterator</code> qui permet d'itérer sur les codets de la chaîne, chaque codet étant renvoyé comme une chaîne.</dd>
</dl>
<h3 id="Méthodes_de_transformation_HTML">Méthodes de transformation HTML</h3>
<p>Ces méthodes ont une utilisation limitée, étant donné qu'elles ne fournissent qu'un petit sous-ensemble des balises et attributs HTML existants.</p>
<dl>
<dt>{{jsxref("String.prototype.anchor()")}} {{deprecated_inline}}</dt>
<dd>{{htmlattrxref("name", "a", "<a name=\"name\">")}} (cible hypertexte)</dd>
<dt>{{jsxref("String.prototype.big()")}} {{deprecated_inline}}</dt>
<dd>{{HTMLElement("big")}}</dd>
<dt>{{jsxref("String.prototype.blink()")}} {{deprecated_inline}}</dt>
<dd>{{HTMLElement("blink")}}</dd>
<dt>{{jsxref("String.prototype.bold()")}} {{deprecated_inline}}</dt>
<dd>{{HTMLElement("b")}}</dd>
<dt>{{jsxref("String.prototype.fixed()")}} {{deprecated_inline}}</dt>
<dd>{{HTMLElement("tt")}}</dd>
<dt>{{jsxref("String.prototype.fontcolor()")}} {{deprecated_inline}}</dt>
<dd>{{htmlattrxref("color", "font", "<font color=\"color\">")}}</dd>
<dt>{{jsxref("String.prototype.fontsize()")}} {{deprecated_inline}}</dt>
<dd>{{htmlattrxref("size", "font", "<font size=\"size\">")}}</dd>
<dt>{{jsxref("String.prototype.italics()")}} {{deprecated_inline}}</dt>
<dd>{{HTMLElement("i")}}</dd>
<dt>{{jsxref("String.prototype.link()")}} {{deprecated_inline}}</dt>
<dd>{{htmlattrxref("href", "a", "<a href=\"url\">")}} (lien vers une URL)</dd>
<dt>{{jsxref("String.prototype.small()")}} {{deprecated_inline}}</dt>
<dd>{{HTMLElement("small")}}</dd>
<dt>{{jsxref("String.prototype.strike()")}} {{deprecated_inline}}</dt>
<dd>{{HTMLElement("strike")}}</dd>
<dt>{{jsxref("String.prototype.sub()")}} {{deprecated_inline}}</dt>
<dd>{{HTMLElement("sub")}}</dd>
<dt>{{jsxref("String.prototype.sup()")}} {{deprecated_inline}}</dt>
<dd>{{HTMLElement("sup")}}</dd>
</dl>
<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">Commentaires</th>
</tr>
<tr>
<td>{{SpecName('ES1')}}</td>
<td>{{Spec2('ES1')}}</td>
<td>Définition initiale.</td>
</tr>
<tr>
<td>{{SpecName('ES5.1', '#sec-15.5.3.1', 'String.prototype')}}</td>
<td>{{Spec2('ES5.1')}}</td>
<td> </td>
</tr>
<tr>
<td>{{SpecName('ES6', '#sec-string.prototype', 'String.prototype')}}</td>
<td>{{Spec2('ES6')}}</td>
<td> </td>
</tr>
<tr>
<td>{{SpecName('ESDraft', '#sec-string.prototype', 'String.prototype')}}</td>
<td>{{Spec2('ESDraft')}}</td>
<td> </td>
</tr>
</tbody>
</table>
<h2 id="Compatibilité_des_navigateurs">Compatibilité des navigateurs</h2>
<p>{{Compat("javascript.builtins.String.prototype")}}</p>
<h2 id="Voir_aussi">Voir aussi</h2>
<ul>
<li>{{jsxref("String")}}</li>
<li>{{jsxref("Function.prototype")}}</li>
</ul>
|