1. String.prototype.charAt(index: number): string: Returns the character(exactly one UTF-16 code unit) at the specified index.

    1
    'hello world'.charAt(1) // returns 'e'
  2. String.prototype.charCodeAt(index: number): number: Returns a number that is the UTF-16 code unit value at the specified index.

    1
    'hello world'.charCodeAt(1) // returns 101
  3. String.prototype.codePointAt(index: string): number: Returns a nonnegative integer Number that is the code point value of the UTF-16 encoded code point starting at the specified index.

    1
    'hello world'.codePointAt(1) // returns 101
  4. String.prototype.concat(str: string, ...rest: string[]): string: Combines the texts and returns a new string.

    1
    'hello world'.concat(', ', 'and welcome') // returns 'hello world, and welcome'
  5. String.prototype.includes(str: string): boolean: Determines whether one string may be found within another string.

    1
    'hello world'.includes('world') // returns true
  6. String.prototype.endsWith(str: string): boolean: Determines whether a string ends with the characters of another string.

    1
    'hello world'.endsWith('world') // returns true
  7. String.prototype.indexOf(str: string): number: Returns the index of the specified string, -1 for not found.

    1
    s.indexOf('world') // returns 6
  8. String.prototype.lastIndexOf(str: string): Returns the index of the specified string, but search starts from the end, -1 for not found

    1
    2
    'world hello world'.indexOf('world') // returns 0
    'world hello world'.lastIndexOf('world') // returns 12
  9. String.prototype.localeCompare(str: string): Returns a number indicating whether a reference string comes before or after or is the same as the given string in sort order.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    const a = 'réservé' // with accents, lowercase
    const b = 'RESERVE' // no accents, uppercase

    console.log(a.localeCompare(b))
    // expected output: 1
    console.log(a.localeCompare(b, 'en', { sensitivity: 'base' }))
    // expected output: 0

    // The letter "a" is before "c" yielding a negative value
    'a'.localeCompare('c') // -2 or -1 (or some other negative value)

    // Alphabetically the word "check" comes after "against" yielding a positive value
    'check'.localeCompare('against') // 2 or 1 (or some other positive value)

    // "a" and "a" are equivalent yielding a neutral value of zero
    'a'.localeCompare('a') // 0
  10. String.prototype.match(regexp): string[] | null: Used to match a regular expression against a string, null for not found

    1
    2
    3
    const paragraph = `The quick brown fox jumps over the lazy dog. It barked`
    const regex = /[A-Z]/g
    paragraph.match(regex) // returns ["T", "I"]
  11. String.prototype.matchAll(regex): Iterator: Returns an iterator of all matches.

  12. String.prototype.normalize: Returns the Unicode Normalization Form of the calling string value.

  13. String.prototype.padEnd(): Pads the current string with a given string(repeated if needed) so that the resulting string reaches a given length. The padding is appliced fromthe end of the current string.

    1
    'Breaded Mushrooms'.padEnd(25, '.') // returns "Breaded Mushrooms........"
  14. String.prototype.padStart(): Pads the current string from the start with a given string to create a new string from a given length

    1
    'Breaded Mushrooms'.padStart(25, '.') // returns "........Breaded Mushrooms"
  15. String.prototype.repeat(times: number): Returns a string consisting of the elements of the object repeated the given times.

    1
    'hello world'.repeat(3) // "hello worldhello worldhello world"
  16. String.prototype.replace(pattern: regexp | string, replacement): string: Returns a new string with some or all matches of a pattern replaced by a replacement

    1
    'hello world'.replace(/world/, 'hello') // returns 'hello hello'
  17. String.prototype.search(pattern: regexp): number: Executes a search for a match between a regular expression and this string, returns the index of matched string.

    1
    'hello world'.search(/ll/) // returns 2
  18. String.prototype.slice(start: number[, end: number]): string: Returns a new string extracted from the original string from [start, end).

    1
    'hello'.slice(1, 2) // returns 'e'
  19. String.prototype.split(pattern): string[]: Splits a string into an array of strings by separating the string into substrings.

    1
    'hello world'.split(' ') // ['hello', 'world']
  20. String.prototype.startsWith(): Determines whether a string begins with the characters of another string.

  21. String.prototype.substring: Returns the characters in a string between two indices into the string.

    1
    'hello world'.substring(1, 2) // returns 'e'

    It seems that the String.prototype.substring works like String.prototype.slice, but if the start > end, String.prototype.substring swaps the two parameters while String.prototype.slice return ‘’.

    1
    2
    'hello world'.substring(2, 1) // returns 'e'
    'hello world'.slice(2, 1) // returns ''

    And String.prototype.slice accepts netagive indices as start from the end of the string, while String.prototype.substring treats negative and NaN as 0.

    Note String.prototype.substr is deprecated

  22. 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 toLowerCase()

  23. 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 toUpperCase()

  24. String.prototype.toLowerCase(): Returns the calling string value converted to lower case.

    1
    'HELLO WORLD'.toLowerCase() // returns 'hello world'
  25. String.prototype.toUpperCase(): Returns the calling string value converted to upper case.

    1
    'hello world'.toUpperCase() // returns 'HELLO WORLD'
  26. String.prototype.toString(): Returns a string representing the specified object.

  27. String.prototype.trim(): Trims whitespaces from the beginning and end of a string

    1
    '   hello world   '.trim() // returns 'hello wrold'
  28. String.prototype.trimStart(), String.prototype.trimLeft(): Trims whitespaces from the beginning of the string.

    1
    '   hello world   '.trimStart() // returns 'hello world   '
  29. String.prototype.trimEnd(), String.prototype.trimRight(): Trims whitespace from the end of the string.

    1
    '   hello world   '.trimEnd() // return '   hello world'
  30. String.prototype.valueOf: Returns the primitive value of the specified object.