String

String

Source:

Methods

endsWith(searchString, lengthopt) → {boolean}

Source:

Determines whether a string ends with the characters of a specified string. From ECMA-262 6 edition. MDN

Example
var str = 'To be, or not to be, that is the question.';

str.endsWith('question.');  // true
str.endsWith('to be');      // false
str.endsWith('to be', 19);  // true
Parameters:
Name Type Attributes Description
searchString string

The characters to be searched for at the end of str.

length number <optional>

If provided, it is used as the length of str. Defaults to str.length

Returns:
  • true if the given characters are found at the end of the string; otherwise, false.
Type
boolean

includes(searchString, positionopt) → {boolean}

Source:

Determines whether one string may be found within another string, returning true or false as appropriate. From ECMA-262 6 edition. MDN

Example
var str = 'To be, or not to be, that is the question.';

str.includes('To be');        // true
str.includes('question');     // true
str.includes('nonexistent');  // false
str.includes('To be', 1);     // false
str.includes('TO BE');        // false
str.includes('');             // true
Parameters:
Name Type Attributes Description
searchString string

The string to be searched.

position number <optional>

The position within the string at which to begin searching for searchString. (Defaults to 0.)

Returns:
  • true if the search string is found anywhere within the given string; otherwise, false if not.
Type
boolean

startsWith(searchString, positionopt) → {boolean}

Source:

Determines whether a string begins with the characters of a specified string. From ECMA-262 6 edition. MDN

Example
var str = 'To be, or not to be, that is the question.';

str.startsWith('To be');          // true
str.startsWith('not to be');      // false
str.startsWith('not to be', 10);  // true
Parameters:
Name Type Attributes Description
searchString string

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

position number <optional>

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

Returns:
  • true if the given characters are found at the beginning of the string; otherwise, false.
Type
boolean

trim() → {string}

Source:

Removes whitespace from both ends of a string. From ECMA-262 5.1 edition. MDN

Example
'   Hello world!   '.trim(); // 'Hello world!'
'Hello world!   '.trim(); // 'Hello world!'
'   Hello world!'.trim(); // 'Hello world!'
'\tHello world!\t'.trim(); // 'Hello world!'
' Hello world! '.trim(); // ' Hello world! '
Returns:
  • A new string representing the calling string stripped of whitespace from both ends.
Type
string