recursal/MDN huggingface dataset:
String.prototype.trimStart()
============================

The **`trimStart()`** method of `String` values removes whitespace from the beginning of this string and returns a new string, without modifying the original string. `trimLeft()` is an alias of this method.

Try it
------

Syntax
------


```js
trimStart()

trimLeft()
```

### Parameters

None.

### Return value

A new string representing `str` stripped of whitespace from its beginning (left side). Whitespace is defined as white space characters plus line terminators.

If the beginning of `str` has no whitespace, a new string is still returned (essentially a copy of `str`).

### Aliasing

After `trim()` was standardized, engines also implemented the non-standard method `trimLeft`. However, for consistency with `padStart()`, when the method got standardized, its name was chosen as `trimStart`. For web compatibility reasons, `trimLeft` remains as an alias to `trimStart`, and they refer to the exact same function object. In some engines this means:


```js
String.prototype.trimLeft.name === "trimStart";
```

Examples
--------

### Using trimStart()

The following example trims whitespace from the start of `str`, but not from its end.


```js
let str = " foo ";

console.log(str.length); // 8

str = str.trimStart();
console.log(str.length); // 5
console.log(str); // 'foo '
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-string.prototype.trimstart |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill of `String.prototype.trimStart` in `core-js`
* `String.prototype.trim()`
* `String.prototype.trimEnd()`
String.prototype.includes()
===========================

The **`includes()`** method of `String` values performs a case-sensitive search to determine whether a given string may be found within this string, returning `true` or `false` as appropriate.

Try it
------

Syntax
------


```js
includes(searchString)
includes(searchString, position)
```

### Parameters

`searchString`

A string to be searched for within `str`. Cannot be a regex. All values that are not regexes are coerced to strings, so omitting it or passing `undefined` causes `includes()` to search for the string `"undefined"`, which is rarely what you want.

`position` Optional

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

### Return value

**`true`** if the search string is found anywhere within the given string, including when `searchString` is an empty string; otherwise, **`false`**.

### Exceptions

`TypeError`

Thrown if `searchString` is a regex.

Description
-----------

This method lets you determine whether or not a string includes another string.

### Case-sensitivity

The `includes()` method is case sensitive. For example, the following expression returns `false`:


```js
"Blue Whale".includes("blue"); // returns false
```


You can work around this constraint by transforming both the original string and the search string to all lowercase:


```js
"Blue Whale".toLowerCase().includes("blue"); // returns true
```

Examples
--------

### Using includes()


```js
const str = "To be, or not to be, that is the question.";

console.log(str.includes("To be")); // true
console.log(str.includes("question")); // true
console.log(str.includes("nonexistent")); // false
console.log(str.includes("To be", 1)); // false
console.log(str.includes("TO BE")); // false
console.log(str.includes("")); // true
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-string.prototype.includes |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill of `String.prototype.includes` in `core-js`
* `Array.prototype.includes()`
* `TypedArray.prototype.includes()`
* `String.prototype.indexOf()`
* `String.prototype.lastIndexOf()`
* `String.prototype.startsWith()`
* `String.prototype.endsWith()`
String.prototype.toUpperCase()
==============================

The **`toUpperCase()`** method of `String` values returns this string converted to uppercase.

Try it
------

Syntax
------


```js
toUpperCase()
```

### Parameters

None.

### Return value

A new string representing the calling string converted to upper case.

Description
-----------

 The `toUpperCase()` method returns the value of the string converted to
 uppercase. This method does not affect the value of the string itself since JavaScript
 strings are immutable.

Examples
--------

### Basic usage


```js
console.log("alphabet".toUpperCase()); // 'ALPHABET'
```

### Conversion of non-string `this` values to strings

 This method will convert any non-string value to a string, when you set its
 `this` to a value that is not a string:


```js
const a = String.prototype.toUpperCase.call({
  toString() {
    return "abcdef";
  },
});

const b = String.prototype.toUpperCase.call(true);

// prints out 'ABCDEF TRUE'.
console.log(a, b);
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-string.prototype.touppercase |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `String.prototype.toLocaleLowerCase()`
* `String.prototype.toLocaleUpperCase()`
* `String.prototype.toLowerCase()`
String.prototype.valueOf()
==========================

The **`valueOf()`** method of `String` values returns this string value.

Try it
------

Syntax
------


```js
valueOf()
```

### Parameters

None.

### Return value

A string representing the primitive value of a given `String` object.

Description
-----------

 The `valueOf()` method of `String` returns the primitive value
 of a `String` object as a string data type. This value is equivalent to
 `String.prototype.toString()`.

This method is usually called internally by JavaScript and not explicitly in code.

Examples
--------

### Using `valueOf()`


```js
const x = new String("Hello world");
console.log(x.valueOf()); // 'Hello world'
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-string.prototype.valueof |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `String.prototype.toString()`
* `Object.prototype.valueOf()`
String.prototype.sub()
======================

**Deprecated:** This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

The **`sub()`** method of `String` values creates a string that embeds this string in a `<sub>` element (`<sub>str</sub>`), which causes this string to be displayed as subscript.

**Note:** All HTML wrapper methods are deprecated and only standardized for compatibility purposes. Use DOM APIs such as `document.createElement()` instead.

Syntax
------


```js
sub()
```

### Parameters

None.

### Return value

A string beginning with a `<sub>` start tag, then the text `str`, and then a `</sub>` end tag.

Examples
--------

### Using sub()

The code below creates an HTML string and then replaces the document's body with it:


```js
const contentString = "Hello, world";

document.body.innerHTML = contentString.sub();
```


This will create the following HTML:


```html
<sub>Hello, world</sub>
```


Instead of using `sub()` and creating HTML text directly, you should use DOM APIs such as `document.createElement()`. For example:


```js
const contentString = "Hello, world";
const elem = document.createElement("sub");
elem.innerText = contentString;
document.body.appendChild(elem);
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-string.prototype.sub |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill of `String.prototype.sub` in `core-js`
* HTML wrapper methods
* `<sub>`
String.prototype.fontcolor()
============================

**Deprecated:** This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

The **`fontcolor()`** method of `String` values creates a string that embeds this string in a `<font>` element (`<font color="...">str</font>`), which causes this string to be displayed in the specified font color.

**Note:** All HTML wrapper methods are deprecated and only standardized for compatibility purposes. For the case of `fontcolor()`, the `<font>` element itself has been removed from the HTML specification and shouldn't be used anymore. Web developers should use CSS properties instead.

Syntax
------


```js
fontcolor(color)
```

### Parameters

`color`

A string expressing the color as a hexadecimal RGB triplet or as a string literal. String literals for color names are listed in the CSS color reference.

### Return value

A string beginning with a `<font color="color">` start tag (double quotes in `color` are replaced with `&quot;`), then the text `str`, and then a `</font>` end tag.

Description
-----------

The `fontcolor()` method itself simply joins the string parts together without any validation or normalization. However, to create valid `<font>` elements, if you express color as a hexadecimal RGB triplet, you must use the format `rrggbb`. For example, the hexadecimal RGB values for salmon are red=FA, green=80, and blue=72, so the RGB triplet for salmon is `"FA8072"`.

Examples
--------

### Using fontcolor()

The code below creates an HTML string and then replaces the document's body with it:


```js
const contentString = "Hello, world";

document.body.innerHTML = contentString.fontcolor("red");
```


This will create the following HTML:


```html
<font color="red">Hello, world</font>
```


**Warning:** This markup is invalid, because `font` is no longer a valid element.

Instead of using `fontcolor()` and creating HTML text directly, you should use CSS to manipulate fonts. For example, you can manipulate `color` through the `element.style` attribute:


```js
document.getElementById("yourElemId").style.color = "red";
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-string.prototype.fontcolor |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill of `String.prototype.fontcolor` in `core-js`
* HTML wrapper methods
* `<font>`
String.prototype.anchor()
=========================

**Deprecated:** This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

The **`anchor()`** method of `String` values creates a string that embeds this string in an `<a>` element with a name (`<a name="...">str</a>`).

**Note:** All HTML wrapper methods are deprecated and only standardized for compatibility purposes. Use DOM APIs such as `document.createElement()` instead.

The HTML specification no longer allows the `<a>` element to have a `name` attribute, so this method doesn't even create valid markup.

Syntax
------


```js
anchor(name)
```

### Parameters

`name`

A string representing a `name` value to put into the generated `<a name="...">` start tag.

### Return value

A string beginning with an `<a name="name">` start tag (double quotes in `name` are replaced with `&quot;`), then the text `str`, and then an `</a>` end tag.

Examples
--------

### Using anchor()

The code below creates an HTML string and then replaces the document's body with it:


```js
const contentString = "Hello, world";

document.body.innerHTML = contentString.anchor("hello");
```


This will create the following HTML:


```html
<a name="hello">Hello, world</a>
```


**Warning:** This markup is invalid, because `name` is no longer a valid attribute of the `<a>` element.

Instead of using `anchor()` and creating HTML text directly, you should use DOM APIs such as `document.createElement()`. For example:


```js
const contentString = "Hello, world";
const elem = document.createElement("a");
elem.innerText = contentString;
document.body.appendChild(elem);
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-string.prototype.anchor |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill of `String.prototype.anchor` in `core-js`
* HTML wrapper methods
* `<a>`
String.prototype.at()
=====================

The **`at()`** method of `String` values takes an integer value and returns a new `String` consisting of the single UTF-16 code unit located at the specified offset. This method allows for positive and negative integers. Negative integers count back from the last string character.

Try it
------

Syntax
------


```js
at(index)
```

### Parameters

`index`

The index (position) of the string character to be returned. Supports relative indexing from the end of the string when passed a negative index; i.e. if a negative number is used, the character returned will be found by counting back from the end of the string.

### Return value

A `String` consisting of the single UTF-16 code unit located at the specified position. Returns `undefined` if the given index can not be found.

Examples
--------

### Return the last character of a string

The following example provides a function which returns the last character found in a specified string.


```js
// A function which returns the last character of a given string
function returnLast(arr) {
  return arr.at(-1);
}

let invoiceRef = "myinvoice01";

console.log(returnLast(invoiceRef)); // '1'

invoiceRef = "myinvoice02";

console.log(returnLast(invoiceRef)); // '2'
```

### Comparing methods

Here we compare different ways to select the penultimate (last but one) character of a `String`. Whilst all below methods are valid, it highlights the succinctness and readability of the `at()` method.


```js
const myString = "Every green bus drives fast.";

// Using length property and charAt() method
const lengthWay = myString.charAt(myString.length - 2);
console.log(lengthWay); // 't'

// Using slice() method
const sliceWay = myString.slice(-2, -1);
console.log(sliceWay); // 't'

// Using at() method
const atWay = myString.at(-2);
console.log(atWay); // 't'
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-string.prototype.at |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill of `String.prototype.at` in `core-js`
* `String.prototype.indexOf()`
* `String.prototype.lastIndexOf()`
* `String.prototype.charCodeAt()`
* `String.prototype.codePointAt()`
* `String.prototype.split()`
String.prototype.trim()
=======================

The **`trim()`** method of `String` values removes whitespace from both ends of this string and returns a new string, without modifying the original string.

To return a new string with whitespace trimmed from just one end, use `trimStart()` or `trimEnd()`.

Try it
------

Syntax
------


```js
trim()
```

### Parameters

None.

### Return value

A new string representing `str` stripped of whitespace from both its beginning and end. Whitespace is defined as white space characters plus line terminators.

If neither the beginning or end of `str` has any whitespace, a new string is still returned (essentially a copy of `str`).

Examples
--------

### Using trim()

The following example trims whitespace from both ends of `str`.


```js
const str = " foo ";
console.log(str.trim()); // 'foo'
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-string.prototype.trim |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `String.prototype.trimStart()`
* `String.prototype.trimEnd()`
String.prototype.search()
=========================

The **`search()`** method of `String` values executes a search for a match between a regular expression and this string, returning the index of the first match in the string.

Try it
------

Syntax
------


```js
search(regexp)
```

### Parameters

`regexp`

A regular expression object, or any object that has a `Symbol.search` method.

If `regexp` is not a `RegExp` object and does not have a `Symbol.search` method, it is implicitly converted to a `RegExp` by using `new RegExp(regexp)`.

### Return value

The index of the first match between the regular expression and the given string, or `-1` if no match was found.

Description
-----------

The implementation of `String.prototype.search()` itself is very simple — it simply calls the `Symbol.search` method of the argument with the string as the first parameter. The actual implementation comes from `RegExp.prototype[@@search]()`.

The `g` flag of `regexp` has no effect on the `search()` result, and the search always happens as if the regex's `lastIndex` is 0. For more information on the behavior of `search()`, see `RegExp.prototype[@@search]()`.

When you want to know whether a pattern is found, and *also* know its index within a string, use `search()`.

* If you only want to know if it exists, use the `RegExp.prototype.test()` method, which returns a boolean.
* If you need the content of the matched text, use `String.prototype.match()` or `RegExp.prototype.exec()`.
Examples
--------

### Using search()

The following example searches a string with two different regex objects to show a successful search (positive value) vs. an unsuccessful search (`-1`).


```js
const str = "hey JudE";
const re = /[A-Z]/;
const reDot = /[.]/;
console.log(str.search(re)); // returns 4, which is the index of the first capital letter "J"
console.log(str.search(reDot)); // returns -1 cannot find '.' dot punctuation
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-string.prototype.search |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill of `String.prototype.search` in `core-js` with fixes and implementation of modern behavior like `Symbol.search` support
* Regular expressions guide
* `String.prototype.match()`
* `RegExp.prototype.exec()`
* `RegExp.prototype[@@search]()`
String.prototype.toLocaleLowerCase()
====================================

The **`toLocaleLowerCase()`** method of `String` values returns this string converted to lower case, according to any locale-specific case mappings.

Try it
------

Syntax
------


```js
toLocaleLowerCase()
toLocaleLowerCase(locales)
```

### Parameters

`locales` Optional

A string with a BCP 47 language tag, or an array of such strings. Indicates the locale to be used to convert to lower case according to any locale-specific case mappings. For the general form and interpretation of the `locales` argument, see the parameter description on the `Intl` main page.

Unlike other methods that use the `locales` argument, `toLocaleLowerCase()` does not allow locale matching. Therefore, after checking the validity of the `locales` argument, `toLocaleLowerCase()` always uses the first locale in the list (or the default locale if the list is empty), even if this locale is not supported by the implementation.

### Return value

 A new string representing the calling string converted to lower case, according to any
 locale-specific case mappings.

Description
-----------

 The `toLocaleLowerCase()` method returns the value of the string converted
 to lower case according to any locale-specific case mappings.
 `toLocaleLowerCase()` does not affect the value of the string itself. In most
 cases, this will produce the same result as `toLowerCase()`, but for some locales, such as Turkish, whose case mappings do not
 follow the default case mappings in Unicode, there may be a different result.

Examples
--------

### Using toLocaleLowerCase()


```js
"ALPHABET".toLocaleLowerCase(); // 'alphabet'

"\u0130".toLocaleLowerCase("tr") === "i"; // true
"\u0130".toLocaleLowerCase("en-US") === "i"; // false

const locales = ["tr", "TR", "tr-TR", "tr-u-co-search", "tr-x-turkish"];
"\u0130".toLocaleLowerCase(locales) === "i"; // true
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-string.prototype.tolocalelowercase |
| ECMAScript Internationalization API Specification # sup-string.prototype.tolocalelowercase |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `String.prototype.toLocaleUpperCase()`
* `String.prototype.toLowerCase()`
* `String.prototype.toUpperCase()`
String.prototype.trimEnd()
==========================

The **`trimEnd()`** method of `String` values removes whitespace from the end of this string and returns a new string, without modifying the original string. `trimRight()` is an alias of this method.

Try it
------

Syntax
------


```js
trimEnd()

trimRight()
```

### Parameters

None.

### Return value

A new string representing `str` stripped of whitespace from its end (right side). Whitespace is defined as white space characters plus line terminators.

If the end of `str` has no whitespace, a new string is still returned (essentially a copy of `str`).

### Aliasing

After `trim()` was standardized, engines also implemented the non-standard method `trimRight`. However, for consistency with `padEnd()`, when the method got standardized, its name was chosen as `trimEnd`. For web compatibility reasons, `trimRight` remains as an alias to `trimEnd`, and they refer to the exact same function object. In some engines this means:


```js
String.prototype.trimRight.name === "trimEnd";
```

Examples
--------

### Using trimEnd()

The following example trims whitespace from the end of `str`, but not from its start.


```js
let str = " foo ";

console.log(str.length); // 8

str = str.trimEnd();
console.log(str.length); // 6
console.log(str); // ' foo'
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-string.prototype.trimend |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill of `String.prototype.trimEnd` in `core-js`
* `String.prototype.trim()`
* `String.prototype.trimStart()`