---
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
---
{{JSRef}}
The String.prototype
property represents the {{jsxref("String")}} prototype object.
{{js_property_attributes(0, 0, 0)}}
Description
All {{jsxref("String")}} instances inherit from String.prototype
. Changes to the String
prototype object are propagated to all {{jsxref("String")}} instances.
Properties
String.prototype.constructor
- Specifies the function that creates an object's prototype.
- {{jsxref("String.prototype.length")}}
- Reflects the length of the string.
N
- Used to access the character in the Nth position where N is a positive integer between 0 and one less than the value of {{jsxref("String.length", "length")}}. These properties are read-only.
Methods
- {{jsxref("String.prototype.charAt()")}}
- Returns the character (exactly one UTF-16 code unit) at the specified index.
- {{jsxref("String.prototype.charCodeAt()")}}
- Returns a number that is the UTF-16 code unit value at the given index.
- {{jsxref("String.prototype.codePointAt()")}}
- Returns a nonnegative integer Number that is the code point value of the UTF-16 encoded code point starting at the specified index.
- {{jsxref("String.prototype.concat()")}}
- Combines the text of two strings and returns a new string.
- {{jsxref("String.prototype.includes()")}}
- Determines whether one string may be found within another string.
- {{jsxref("String.prototype.endsWith()")}}
- Determines whether a string ends with the characters of another string.
- {{jsxref("String.prototype.indexOf()")}}
- Returns the index within the calling {{jsxref("String")}} object of the first occurrence of the specified value, or -1 if not found.
- {{jsxref("String.prototype.lastIndexOf()")}}
- Returns the index within the calling {{jsxref("String")}} object of the last occurrence of the specified value, or -1 if not found.
- {{jsxref("String.prototype.localeCompare()")}}
- Returns a number indicating whether a reference string comes before or after or is the same as the given string in sort order.
- {{jsxref("String.prototype.match()")}}
- Used to match a regular expression against a string.
- {{jsxref("String.prototype.normalize()")}}
- Returns the Unicode Normalization Form of the calling string value.
- {{jsxref("String.prototype.padEnd()")}}
- Pads the current string from the end with a given string to create a new string from a given length.
- {{jsxref("String.prototype.padStart()")}}
- Pads the current string from the start with a given string to create a new string from a given length.
{{jsxref("String.prototype.quote()")}} {{obsolete_inline}}
Wraps the string in double quotes (""
").
- {{jsxref("String.prototype.repeat()")}}
- Returns a string consisting of the elements of the object repeated the given times.
- {{jsxref("String.prototype.replace()")}}
- Used to find a match between a regular expression and a string, and to replace the matched substring with a new substring.
- {{jsxref("String.prototype.search()")}}
- Executes the search for a match between a regular expression and a specified string.
- {{jsxref("String.prototype.slice()")}}
- Extracts a section of a string and returns a new string.
- {{jsxref("String.prototype.split()")}}
- Splits a {{jsxref("Global_Objects/String", "String")}} object into an array of strings by separating the string into substrings.
- {{jsxref("String.prototype.startsWith()")}}
- Determines whether a string begins with the characters of another string.
- {{jsxref("String.prototype.substr()")}}
- Returns the characters in a string beginning at the specified location through the specified number of characters.
- {{jsxref("String.prototype.substring()")}}
- Returns the characters in a string between two indexes into the string.
- {{jsxref("String.prototype.toLocaleLowerCase()")}}
- 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()")}}.
- {{jsxref("String.prototype.toLocaleUpperCase()")}}
- 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()")}}.
- {{jsxref("String.prototype.toLowerCase()")}}
- Returns the calling string value converted to lower case.
- {{jsxref("String.prototype.toSource()")}} {{non-standard_inline}}
- 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.
- {{jsxref("String.prototype.toString()")}}
- Returns a string representing the specified object. Overrides the {{jsxref("Object.prototype.toString()")}} method.
- {{jsxref("String.prototype.toUpperCase()")}}
- Returns the calling string value converted to uppercase.
- {{jsxref("String.prototype.trim()")}}
- Trims whitespace from the beginning and end of the string. Part of the ECMAScript 5 standard.
- {{jsxref("String.prototype.trimLeft()")}} {{non-standard_inline}}
- Trims whitespace from the left side of the string.
- {{jsxref("String.prototype.trimRight()")}} {{non-standard_inline}}
- Trims whitespace from the right side of the string.
- {{jsxref("String.prototype.valueOf()")}}
- Returns the primitive value of the specified object. Overrides the {{jsxref("Object.prototype.valueOf()")}} method.
- {{jsxref("String.prototype.@@iterator()", "String.prototype[@@iterator]()")}}
- Returns a new
Iterator
object that iterates over the code points of a String value, returning each code point as a String value.
HTML wrapper methods
These methods are of limited use, as they provide only a subset of the available HTML tags and attributes.
- {{jsxref("String.prototype.anchor()")}}
- {{htmlattrxref("name", "a", "<a name=\"name\">")}} (hypertext target)
- {{jsxref("String.prototype.big()")}} {{deprecated_inline}}
- {{HTMLElement("big")}}
- {{jsxref("String.prototype.blink()")}} {{deprecated_inline}}
- {{HTMLElement("blink")}}
- {{jsxref("String.prototype.bold()")}} {{deprecated_inline}}
- {{HTMLElement("b")}}
- {{jsxref("String.prototype.fixed()")}} {{deprecated_inline}}
- {{HTMLElement("tt")}}
- {{jsxref("String.prototype.fontcolor()")}} {{deprecated_inline}}
- {{htmlattrxref("color", "font", "<font color=\"color\">")}}
- {{jsxref("String.prototype.fontsize()")}} {{deprecated_inline}}
- {{htmlattrxref("size", "font", "<font size=\"size\">")}}
- {{jsxref("String.prototype.italics()")}} {{deprecated_inline}}
- {{HTMLElement("i")}}
- {{jsxref("String.prototype.link()")}}
- {{htmlattrxref("href", "a", "<a href=\"url\">")}} (link to URL)
- {{jsxref("String.prototype.small()")}} {{deprecated_inline}}
- {{HTMLElement("small")}}
- {{jsxref("String.prototype.strike()")}} {{deprecated_inline}}
- {{HTMLElement("strike")}}
- {{jsxref("String.prototype.sub()")}} {{deprecated_inline}}
- {{HTMLElement("sub")}}
- {{jsxref("String.prototype.sup()")}} {{deprecated_inline}}
- {{HTMLElement("sup")}}
Specifications
Specification |
Status |
Comment |
{{SpecName('ES1')}} |
{{Spec2('ES1')}} |
Initial definition. |
{{SpecName('ES5.1', '#sec-15.5.3.1', 'String.prototype')}} |
{{Spec2('ES5.1')}} |
|
{{SpecName('ES6', '#sec-string.prototype', 'String.prototype')}} |
{{Spec2('ES6')}} |
|
{{SpecName('ESDraft', '#sec-string.prototype', 'String.prototype')}} |
{{Spec2('ESDraft')}} |
|
Browser compatibility
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
{{Compat("javascript.builtins.String.prototype")}}
See also
- {{jsxref("String")}}
- {{jsxref("Function.prototype")}}