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
|
---
title: String.prototype
slug: conflicting/Web/JavaScript/Reference/Global_Objects/String
translation_of: Web/JavaScript/Reference/Global_Objects/String
translation_of_original: Web/JavaScript/Reference/Global_Objects/String/prototype
original_slug: Web/JavaScript/Reference/Global_Objects/String/prototype
---
<div>{{JSRef}}</div>
<p>The <strong><code>String.prototype</code></strong> property represents the {{jsxref("String")}} prototype object.</p>
<div>{{js_property_attributes(0, 0, 0)}}</div>
<h2 id="Description">Description</h2>
<p>All {{jsxref("String")}} instances inherit from <code>String.prototype</code>. Changes to the <code>String</code> prototype object are propagated to all {{jsxref("String")}} instances.</p>
<h2 id="Properties">Properties</h2>
<dl>
<dt><code>String.prototype.constructor</code></dt>
<dd>Specifies the function that creates an object's prototype.</dd>
<dt>{{jsxref("String.prototype.length")}}</dt>
<dd>Reflects the length of the string.</dd>
<dt><code><em>N</em></code></dt>
<dd>Used to access the character in the <em>N</em>th position where <em>N</em> is a positive integer between 0 and one less than the value of {{jsxref("String.length", "length")}}. These properties are read-only.</dd>
</dl>
<h2 id="Methods">Methods</h2>
<h3 id="Methods_unrelated_to_HTML">Methods unrelated to HTML</h3>
<dl>
<dt>{{jsxref("String.prototype.charAt()")}}</dt>
<dd>Returns the character (exactly one UTF-16 code unit) at the specified index.</dd>
<dt>{{jsxref("String.prototype.charCodeAt()")}}</dt>
<dd>Returns a number that is the UTF-16 code unit value at the given index.</dd>
<dt>{{jsxref("String.prototype.codePointAt()")}}</dt>
<dd>Returns a nonnegative integer Number that is the code point value of the UTF-16 encoded code point starting at the specified index.</dd>
<dt>{{jsxref("String.prototype.concat()")}}</dt>
<dd>Combines the text of two strings and returns a new string.</dd>
<dt>{{jsxref("String.prototype.includes()")}}</dt>
<dd>Determines whether one string may be found within another string.</dd>
<dt>{{jsxref("String.prototype.endsWith()")}}</dt>
<dd>Determines whether a string ends with the characters of another string.</dd>
<dt>{{jsxref("String.prototype.indexOf()")}}</dt>
<dd>Returns the index within the calling {{jsxref("String")}} object of the first occurrence of the specified value, or -1 if not found.</dd>
<dt>{{jsxref("String.prototype.lastIndexOf()")}}</dt>
<dd>Returns the index within the calling {{jsxref("String")}} object of the last occurrence of the specified value, or -1 if not found.</dd>
<dt>{{jsxref("String.prototype.localeCompare()")}}</dt>
<dd>Returns a number indicating whether a reference string comes before or after or is the same as the given string in sort order.</dd>
<dt>{{jsxref("String.prototype.match()")}}</dt>
<dd>Used to match a regular expression against a string.</dd>
<dt>{{jsxref("String.prototype.normalize()")}}</dt>
<dd>Returns the Unicode Normalization Form of the calling string value.</dd>
<dt>{{jsxref("String.prototype.padEnd()")}}</dt>
<dd>Pads the current string from the end with a given string to create a new string from a given length.</dd>
<dt>{{jsxref("String.prototype.padStart()")}}</dt>
<dd>Pads the current string from the start with a given string to create a new string from a given length.</dd>
<dt><s class="obsoleteElement">{{jsxref("String.prototype.quote()")}} {{obsolete_inline}}</s></dt>
<dd><s class="obsoleteElement">Wraps the string in double quotes ("<code>"</code>").</s></dd>
<dt>{{jsxref("String.prototype.repeat()")}}</dt>
<dd>Returns a string consisting of the elements of the object repeated the given times.</dd>
<dt>{{jsxref("String.prototype.replace()")}}</dt>
<dd>Used to find a match between a regular expression and a string, and to replace the matched substring with a new substring.</dd>
<dt>{{jsxref("String.prototype.search()")}}</dt>
<dd>Executes the search for a match between a regular expression and a specified string.</dd>
<dt>{{jsxref("String.prototype.slice()")}}</dt>
<dd>Extracts a section of a string and returns a new string.</dd>
<dt>{{jsxref("String.prototype.split()")}}</dt>
<dd>Splits a {{jsxref("Global_Objects/String", "String")}} object into an array of strings by separating the string into substrings.</dd>
<dt>{{jsxref("String.prototype.startsWith()")}}</dt>
<dd>Determines whether a string begins with the characters of another string.</dd>
<dt>{{jsxref("String.prototype.substr()")}}</dt>
<dd>Returns the characters in a string beginning at the specified location through the specified number of characters.</dd>
<dt>{{jsxref("String.prototype.substring()")}}</dt>
<dd>Returns the characters in a string between two indexes into the string.</dd>
<dt>{{jsxref("String.prototype.toLocaleLowerCase()")}}</dt>
<dd>The characters within a string are converted to lower case while respecting the current locale. For most languages, this will return the same as {{jsxref("String.prototype.toLowerCase()", "toLowerCase()")}}.</dd>
<dt>{{jsxref("String.prototype.toLocaleUpperCase()")}}</dt>
<dd>The characters within a string are converted to upper case while respecting the current locale. For most languages, this will return the same as {{jsxref("String.prototype.toUpperCase()", "toUpperCase()")}}.</dd>
<dt>{{jsxref("String.prototype.toLowerCase()")}}</dt>
<dd>Returns the calling string value converted to lower case.</dd>
<dt>{{jsxref("String.prototype.toSource()")}} {{non-standard_inline}}</dt>
<dd>Returns an object literal representing the specified object; you can use this value to create a new object. Overrides the {{jsxref("Object.prototype.toSource()")}} method.</dd>
<dt>{{jsxref("String.prototype.toString()")}}</dt>
<dd>Returns a string representing the specified object. Overrides the {{jsxref("Object.prototype.toString()")}} method.</dd>
<dt>{{jsxref("String.prototype.toUpperCase()")}}</dt>
<dd>Returns the calling string value converted to uppercase.</dd>
<dt>{{jsxref("String.prototype.trim()")}}</dt>
<dd>Trims whitespace from the beginning and end of the string. Part of the ECMAScript 5 standard.</dd>
<dt>{{jsxref("String.prototype.trimLeft()")}} {{non-standard_inline}}</dt>
<dd>Trims whitespace from the left side of the string.</dd>
<dt>{{jsxref("String.prototype.trimRight()")}} {{non-standard_inline}}</dt>
<dd>Trims whitespace from the right side of the string.</dd>
<dt>{{jsxref("String.prototype.valueOf()")}}</dt>
<dd>Returns the primitive value of the specified object. Overrides the {{jsxref("Object.prototype.valueOf()")}} method.</dd>
<dt>{{jsxref("String.prototype.@@iterator()", "String.prototype[@@iterator]()")}}</dt>
<dd>Returns a new <code>Iterator</code> object that iterates over the code points of a String value, returning each code point as a String value.</dd>
</dl>
<h3 id="HTML_wrapper_methods">HTML wrapper methods</h3>
<p>These methods are of limited use, as they provide only a subset of the available HTML tags and attributes.</p>
<dl>
<dt>{{jsxref("String.prototype.anchor()")}}</dt>
<dd>{{htmlattrxref("name", "a", "<a name=\"name\">")}} (hypertext target)</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()")}}</dt>
<dd>{{htmlattrxref("href", "a", "<a href=\"url\">")}} (link to 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="Specifications">Specifications</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
<tr>
<td>{{SpecName('ES1')}}</td>
<td>{{Spec2('ES1')}}</td>
<td>Initial definition.</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="Browser_compatibility">Browser compatibility</h2>
<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p>
<p>{{Compat("javascript.builtins.String.prototype")}}</p>
<h2 id="See_also">See also</h2>
<ul>
<li>{{jsxref("String")}}</li>
<li>{{jsxref("Function.prototype")}}</li>
</ul>
|