Class: String

String

The JavaScript String class.

new String()

Source:
See:

Methods

appendParams(params) → {String}

Appends query string parameters to a URL.

Parameters:
Name Type Description
params String

Query string parameters.

Source:
Returns:
Type
String

A reference to the string (chainable).

Example
var url = "www.google.com";
url = url.appendParams('lang=en'); // -> "www.google.com?lang=en"
url = url.appendParams('a=1&b=2'); // -> "www.google.com?lang=en&a=1&b=2"

endsWith(searchString, position) → {Boolean}

Determines if a string ends with the characters of another string.

Parameters:
Name Type Argument Default Description
searchString String

The characters to be searched for at the end of this string.

position Number <optional>
this.length

Search within this string as if this string were only this long; clamped within the range established by this string's length.

Source:
Returns:
Type
Boolean

true if this string ends with searchString; else false.

Example
var str = "Who am I, Gamling?";
alert( str.endsWith("Gamling?") );  // true
alert( str.endsWith("am I") );      // false
alert( str.endsWith("am I", 8) );   // true

escapeHTML() → {String}

HTML-encodes the string by converting HTML special characters to their entity equivalents and returns the result.

Source:
Returns:
Type
String

The HTML-escaped text.

Example
'<img src="//somesite.com" />'.escapeHTML();  // -> '&lt;img src="//somesite.com" /&gt;'

includes(searchString, position) → {Boolean}

Determines whether the passed in string is in the current string.

Parameters:
Name Type Argument Default Description
searchString String

The string to be searched for.

position Number <optional>
0

The position in this string at which to begin the search.

Source:
Returns:
Type
Boolean

true if this string contains the search string, false otherwise.

Example
var str = "Winter is coming.";
alert( str.includes(" is ") );    // true
alert( str.includes("summer") );  // false

repeat(count) → {String}

Copies the current string a given number of times and returns the new string.

Parameters:
Name Type Description
count Number

An integer between 0 and +∞ : [0, +∞).

Source:
Throws:
RangeError
The repeat count must be positive and less than infinity.
Returns:
Type
String
Example
"abc".repeat(0)   // ""
"abc".repeat(1)   // "abc"
"abc".repeat(2)   // "abcabc"
"abc".repeat(3.5) // "abcabcabc" (count will be converted to integer)
"0".repeat(5)     // "00000"

startsWith(searchString, position) → {Boolean}

Determines whether a string starts with the characters of another string.

Parameters:
Name Type Argument Default Description
searchString String

The characters to be searched for at the start of this string.

position Number <optional>
0

The position in this string at which to begin searching for searchString.

Source:
Returns:
Type
Boolean

true if this string starts with the search string; else false.

Example
var str = "Who am I, Gamling?";
alert( str.endsWith("Who") );      // true
alert( str.endsWith("am I") );     // false
alert( str.endsWith("am I", 4) );  // true

tokenize() → {Array.<String>}

Returns the string split into an array of substrings (tokens) that were separated by white-space.

Source:
Returns:
Type
Array.<String>

An array of tokens.

Example
var str = "The boy who lived.";
str.tokenize(); // -> ["The", "boy", "who", "lived."]

unescapeHTML() → {String}

HTML-decodes the string by converting entities of HTML special characters to their normal form and returns the result.

Source:
Returns:
Type
String

The HTML-unescaped text.

Example
'&lt;img src="//somesite.com" /&gt;'.unescapeHTML();  // -> '<img src="//somesite.com" />'