String
Overview
The String object is used to represent and manipulate a sequence of characters.
For more information see: String (MDN).
Properties Summarized
Gives the length of the string.
Methods Summarized
returns a copy of the string embedded within an anchor <A> tag set.
returns a copy of the string embedded within an <BIG> tag set.
returns a copy of the string embedded within an <BLINK> tag set.
returns a copy of the string embedded within an <B> tag set.
returns a character of the string.
returns a decimal code of the char in the string.
returns a non-negative integer that is the Unicode code point value at the given position.
returns a string that appends the parameter string to the string.
returns a string that appends the parameter string to the string.
Determines whether a string ends with the characters of a specified string, returning true or false as appropriate.
Determines whether a string ends with the characters of a specified string, returning true or false as appropriate.
returns a boolean that checks if the given string is equal to the string
returns a boolean that checks if the given string is equal to the string ignoring case
returns a copy of the string embedded within an anchor <TT> tag set.
returns a copy of the string embedded within an <FONT> tag set, the color param is assigned the the color attribute.
returns a copy of the string embedded within an <FONT> tag set, The size param is set to the SIZE attribute
Static method that returns a string created from the specified sequence of UTF-16 code units.
Static method that returns a string created by using the specified sequence of code points.
Determines whether one string may be found within another string.
returns the found index of the given string in string.
returns a copy of the string embedded within an <I> tag set
returns the found index of the given string in string from the end.
returns a copy of the string embedded within an <A> tag set.
returns an array of strings within the current string that matches the regexp.
Returns the Unicode Normalization Form of the string.
Returns the Unicode Normalization Form of the string.
The padEnd() method pads the current string with a given string (repeated, if needed) so that the resulting string reaches a given length.
The padEnd() method pads the current string with a given string (repeated, if needed) so that the resulting string reaches a given length.
The padStart() method pads the current string with another string (multiple times, if needed) until the resulting string reaches the given length.
The padStart() method pads the current string with another string (multiple times, if needed) until the resulting string reaches the given length.
Constructs and returns a new string which contains the specified number of copies of the string on which it was called, concatenated together.
returns a new string where the matches of the given regexp are replaced by the return value of the function.
returns a new string where the matches of the given reg exp are replaced by newSubStr.
returns a new string where the first match of the given substr is replaced by the return value of the function.
returns a new string where the first match of the given substr is replaced by newSubStr.
returns an index where the first match is found of the regexp
returns a substring of the string.
returns a substring of the string.
returns a copy of the string embedded within an <SMALL> tag set.
returns an array of objects whose elements are segments of the current string.
returns an array of objects whose elements are segments of the current string.
Determines whether a string begins with the characters of a specified string, returning true or false as appropriate.
Determines whether a string begins with the characters of a specified string, returning true or false as appropriate.
returns a copy of the string embedded within an <STRIKE> tag set.
returns a copy of the string embedded within an <SUB> tag set.
returns a substring of the string from the start with the number of chars specified.
returns a substring of the string from the start with the number of chars specified.
Returns a substring of the string from the start index until the end index.
Returns a substring of the string from the start index until the end index.
returns a copy of the string embedded within an <SUP> tag set.
returns a string with all lowercase letters of the current string.
returns a string with all uppercase letters of the current string.
Returns the string stripped of whitespace from both ends.
Removes whitespace from the ending of a string and returns a new string, without modifying the original string.
Removes whitespace from the beginning of a string and returns a new string, without modifying the original string.
Properties Detailed
length
Gives the length of the string.
Type Number
Sample
Methods Detailed
anchor(nameAttribute)
returns a copy of the string embedded within an anchor <A> tag set.
Parameters
String nameAttribute ;
Returns: String
Sample
big()
returns a copy of the string embedded within an <BIG> tag set.
Returns: String
Sample
blink()
returns a copy of the string embedded within an <BLINK> tag set.
Returns: String
Sample
bold()
returns a copy of the string embedded within an <B> tag set.
Returns: String
Sample
charAt(index)
returns a character of the string.
Parameters
Number index ;
Returns: Number
Sample
charCodeAt(index)
returns a decimal code of the char in the string.
Parameters
Number index ;
Returns: Number
Sample
codePointAt(index)
returns a non-negative integer that is the Unicode code point value at the given position. Note that this function does not give the nth code point in a string, but the code point starting at the specified string index.
Parameters
Number index ;
Returns: Number
Sample
concat(string2)
returns a string that appends the parameter string to the string.
Parameters
String string2 ;
Returns: String
Sample
concat(string2, stringN)
returns a string that appends the parameter string to the string.
Parameters
Returns: String
Sample
endsWith(searchString)
Determines whether a string ends with the characters of a specified string, returning true or false as appropriate.
Parameters
String searchString The characters to be searched for at the end of str.
Returns: String true if the given characters are found at the end of the string; otherwise, false
Sample
endsWith(searchString, length)
Determines whether a string ends with the characters of a specified string, returning true or false as appropriate.
Parameters
String searchString The characters to be searched for at the end of str.
Number length If provided, it is used as the length of str. Defaults to str.length.
Returns: String true if the given characters are found at the end of the string; otherwise, false
Sample
equals(other)
returns a boolean that checks if the given string is equal to the string
Parameters
String other ;
Returns: Boolean
Sample
equalsIgnoreCase(other)
returns a boolean that checks if the given string is equal to the string ignoring case
Parameters
String other ;
Returns: Boolean
Sample
fixed()
returns a copy of the string embedded within an anchor <TT> tag set.
Returns: String
Sample
fontcolor(color)
returns a copy of the string embedded within an <FONT> tag set, the color param is assigned the the color attribute.
Parameters
String color ;
Returns: String
Sample
fontsize(size)
returns a copy of the string embedded within an <FONT> tag set, The size param is set to the SIZE attribute
Parameters
Number size ;
Returns: String
Sample
fromCharCode(num)
Static method that returns a string created from the specified sequence of UTF-16 code units.
Parameters
Array num A sequence of numbers that are UTF-16 code units. The range is between 0 and 65535 (0xFFFF). Numbers greater than 0xFFFF are truncated. No validity checks are performed.
Returns: String A string of length N consisting of the N specified UTF-16 code units.
Sample
fromCodePoint(num)
Static method that returns a string created by using the specified sequence of code points. String.fromCharCode() cannot return supplementary characters (i.e. code points 0x010000 – 0x10FFFF) by specifying their code point. Instead, it requires the UTF-16 surrogate pair for that. String.fromCodePoint(), on the other hand, can return 4-byte supplementary characters, as well as the more common 2-byte BMP characters, by specifying their code point (which is equivalent to the UTF-32 code unit).
RangeError is thrown if an invalid Unicode code point is given (e.g. "RangeError: NaN is not a valid code point").
Parameters
Array num A sequence of code points.
Returns: String A string created by using the specified sequence of code points.
Sample
includes()
Determines whether one string may be found within another string.
Returns: String
Sample
indexOf(searchValue, fromIndex)
returns the found index of the given string in string.
Parameters
Returns: Number
Sample
italics()
returns a copy of the string embedded within an <I> tag set
Returns: String
Sample
lastIndexOf(searchValue, fromIndex)
returns the found index of the given string in string from the end.
Parameters
Returns: Number
Sample
link(hrefAttribute)
returns a copy of the string embedded within an <A> tag set.
Parameters
String hrefAttribute ;
Returns: String
Sample
localeCompare(otherString)
Parameters
String otherString ;
Returns: Number
Sample
match(regexp)
returns an array of strings within the current string that matches the regexp.
Parameters
RegExp regexp ;
Returns: Array
Sample
normalize()
Returns the Unicode Normalization Form of the string. (defaults to "NFC" form)
Returns: String A string containing the Unicode Normalization Form of the given string.
normalize(form)
Returns the Unicode Normalization Form of the string. form param can be one of "NFC", "NFD", "NFKC", or "NFKD", specifying the Unicode Normalization Form. If omitted or undefined, "NFC" is used.
These values have the following meanings:
"NFC" Canonical Decomposition, followed by Canonical Composition. "NFD" Canonical Decomposition. "NFKC" Compatibility Decomposition, followed by Canonical Composition. "NFKD" Compatibility Decomposition.
Parameters
String form param can be one of "NFC", "NFD", "NFKC", or "NFKD",
Returns: String A string containing the Unicode Normalization Form of the given string.
Sample
padEnd(targetLength)
The padEnd() method pads the current string with a given string (repeated, if needed) so that the resulting string reaches a given length. The padding is applied from the end of the current string. The default value used for padding is the unicode "space" character (U+0020) - if no padString argument is used.
Parameters
Number targetLength The length of the resulting string once the current str has been padded. If the value is less than or equal to str.length, then str is returned as-is.
Returns: String A String of the specified targetLength with spaces applied at the end of the current str.
Sample
padEnd(targetLength, padString)
The padEnd() method pads the current string with a given string (repeated, if needed) so that the resulting string reaches a given length. The padding is applied from the end of the current string.
Parameters
Number targetLength The length of the resulting string once the current str has been padded. If the value is less than or equal to str.length, then str is returned as-is.
String padString The string to pad the current str with. If padString is too long to stay within the targetLength, it will be truncated from the end. The default value is the unicode "space" character (U+0020).
Returns: String A String of the specified targetLength with the padString applied at the end of the current str.
Sample
padStart(targetLength)
The padStart() method pads the current string with another string (multiple times, if needed) until the resulting string reaches the given length. The padding is applied from the start of the current string. The default value used for padding is the unicode "space" character (U+0020) - if no padString argument is used.
Parameters
Number targetLength The length of the resulting string once the current str has been padded. If the value is less than or equal to str.length, then str is returned as-is.
Returns: String A String of the specified targetLength with spaces applied from the start.
Sample
padStart(targetLength, padString)
The padStart() method pads the current string with another string (multiple times, if needed) until the resulting string reaches the given length. The padding is applied from the start of the current string.
Parameters
Number targetLength The length of the resulting string once the current str has been padded. If the value is less than or equal to str.length, then str is returned as-is.
String padString The string to pad the current str with. If padString is too long to stay within the targetLength, it will be truncated from the end. The default value is the unicode "space" character (U+0020).
Returns: String A String of the specified targetLength with padString applied from the start.
Sample
repeat(count)
Constructs and returns a new string which contains the specified number of copies of the string on which it was called, concatenated together.
Parameters
Number count An integer between 0 and +Infinity, indicating the number of times to repeat the string.
Returns: String A new string containing the specified number of copies of the given string.
Sample
replace(regexp, function)
returns a new string where the matches of the given regexp are replaced by the return value of the function. The function parameter is the function to be invoked to create the new substring (to put in place of the substring received from parameter #1).
Parameters
Returns: String
Sample
replace(regexp, newSubStr)
returns a new string where the matches of the given reg exp are replaced by newSubStr.
Parameters
Returns: String
Sample
replace(substr, function)
returns a new string where the first match of the given substr is replaced by the return value of the function. The function parameter is the function to be invoked to create the new substring (to put in place of the substring received from parameter #1).
Parameters
Returns: String
Sample
replace(substr, newSubStr)
returns a new string where the first match of the given substr is replaced by newSubStr.
Parameters
Returns: String
Sample
search(regexp)
returns an index where the first match is found of the regexp
Parameters
RegExp regexp ;
Returns: Number
Sample
slice(beginSlice)
returns a substring of the string.
Parameters
Number beginSlice ;
Returns: String
Sample
slice(beginSlice, endSlice)
returns a substring of the string.
Parameters
Returns: String
Sample
small()
returns a copy of the string embedded within an <SMALL> tag set.
Returns: String
Sample
split(separator, limit)
returns an array of objects whose elements are segments of the current string.
Parameters
RegExp separator Specifies the string which denotes the points at which each split should occur. If separator is an empty string, str is converted to an array of characters.
Number limit Optional integer specifying a limit on the number of splits to be found.
Returns: String
Sample
split(separator, limit)
returns an array of objects whose elements are segments of the current string.
Parameters
String separator Specifies the string which denotes the points at which each split should occur. If separator is an empty string, str is converted to an array of characters.
Number limit Optional integer specifying a limit on the number of splits to be found.
Returns: String
Sample
startsWith(searchString)
Determines whether a string begins with the characters of a specified string, returning true or false as appropriate.
Parameters
String searchString The characters to be searched for at the start of this string.
Returns: String true if the given characters are found at the beginning of the string; otherwise, false
Sample
startsWith(searchString, position)
Determines whether a string begins with the characters of a specified string, returning true or false as appropriate.
Parameters
String searchString The characters to be searched for at the start of this string.
Number position The position in this string at which to begin searching for searchString. Defaults to 0.
Returns: String true if the given characters are found at the beginning of the string; otherwise, false
Sample
strike()
returns a copy of the string embedded within an <STRIKE> tag set.
Returns: String
Sample
sub()
returns a copy of the string embedded within an <SUB> tag set.
Returns: String
Sample
substr(start)
returns a substring of the string from the start with the number of chars specified.
Parameters
Number start ;
Returns: String
Sample
substr(start, length)
returns a substring of the string from the start with the number of chars specified.
Parameters
Returns: String
Sample
substring(indexA)
Returns a substring of the string from the start index until the end index.
Parameters
Number indexA ;
Returns: String
Sample
substring(indexA, indexB)
Returns a substring of the string from the start index until the end index.
Parameters
Returns: String
Sample
sup()
returns a copy of the string embedded within an <SUP> tag set.
Returns: String
Sample
toLocaleLowerCase()
Returns: String
Sample
toLocaleUpperCase()
Returns: String
Sample
toLowerCase()
returns a string with all lowercase letters of the current string.
Returns: String
Sample
toUpperCase()
returns a string with all uppercase letters of the current string.
Returns: String
Sample
trim()
Returns the string stripped of whitespace from both ends.
Returns: String
Sample
trimEnd()
Removes whitespace from the ending of a string and returns a new string, without modifying the original string.
Returns: String
Sample
trimStart()
Removes whitespace from the beginning of a string and returns a new string, without modifying the original string.
Returns: String
Sample
Last updated