JavaScript String Functions and Properties


Here is a complete list of string functions (methods) and properties in JavaScript:

String Methods (Functions)

  1. charAt(index)

    • Returns the character at the specified index.
    "Hello".charAt(0); // "H"
  2. charCodeAt(index)

    • Returns the Unicode of the character at the specified index.
    "Hello".charCodeAt(0); // 72
  3. codePointAt(index)

    • Returns the code point of the character at the specified index (ES6).
    "ð ®·".codePointAt(0); // 134071
  4. concat(string1, string2, ...)

    • Concatenates one or more strings.
    "Hello".concat(" ", "World"); // "Hello World"
  5. includes(searchString, position)

    • Checks if a string contains a specified string (ES6).
    "Hello World".includes("World"); // true
  6. endsWith(searchString, length)

    • Checks if a string ends with a specified string (ES6).
    "Hello World".endsWith("World"); // true
  7. indexOf(searchValue, fromIndex)

    • Returns the index of the first occurrence of the specified string.
    "Hello World".indexOf("World"); // 6
  8. lastIndexOf(searchValue, fromIndex)

    • Returns the index of the last occurrence of the specified string.
    "Hello World World".lastIndexOf("World"); // 12
  9. localeCompare(compareString)

    • Compares two strings in the current locale.
    "apple".localeCompare("banana"); // -1 (meaning "apple" comes before "banana")
  10. match(regexp)

    • Searches a string for a match against a regular expression.
    "Hello World".match(/World/); // ["World"]
  11. matchAll(regexp)

    • Returns an iterator for all matches against a regular expression (ES2020).
    [..."Hello World".matchAll(/l/g)]; // ["l", "l", "l"]
  12. normalize(form)

    • Returns the Unicode normalization form of a string (ES6).
    "\u004E\u0303".normalize(); // "Ñ"
  13. padEnd(targetLength, padString)

    • Pads the current string with another string until it reaches the target length (ES2017).
    "5".padEnd(4, "0"); // "5000"
  14. padStart(targetLength, padString)

    • Pads the current string from the start with another string (ES2017).
    "5".padStart(4, "0"); // "0005"
  15. repeat(count)

    • Returns a new string that repeats the original string count times (ES6).
    "Hello".repeat(3); // "HelloHelloHello"
  16. replace(searchValue, newValue)

    • Replaces the first occurrence of a string or regex pattern with a new string.
    "Hello World".replace("World", "Universe"); // "Hello Universe"
  17. replaceAll(searchValue, newValue)

    • Replaces all occurrences of a string or regex pattern (ES2021).
    "World World".replaceAll("World", "Universe"); // "Universe Universe"
  18. search(regexp)

    • Searches for a match between the string and a regular expression.
    "Hello World".search(/World/); // 6
  19. slice(startIndex, endIndex)

    • Extracts a part of a string.
    "Hello World".slice(0, 5); // "Hello"
  20. split(separator, limit)

    • Splits a string into an array of substrings.
    "Hello World".split(" "); // ["Hello", "World"]
  21. startsWith(searchString, position)

    • Checks if a string starts with a specified string (ES6).
    "Hello World".startsWith("Hello"); // true
  22. substring(startIndex, endIndex)

    • Extracts characters between two indices.
    "Hello World".substring(0, 5); // "Hello"
  23. toLowerCase()

    • Converts a string to lowercase.
    "Hello World".toLowerCase(); // "hello world"
  24. toUpperCase()

    • Converts a string to uppercase.
    "Hello World".toUpperCase(); // "HELLO WORLD"
  25. trim()

    • Removes whitespace from both sides of a string.
    " Hello World ".trim(); // "Hello World"
  26. trimStart() / trimLeft()

    • Removes whitespace from the beginning of a string (ES2019).
    " Hello World ".trimStart(); // "Hello World "
  27. trimEnd() / trimRight()

    • Removes whitespace from the end of a string (ES2019).
    " Hello World ".trimEnd(); // " Hello World"
  28. toLocaleLowerCase()

    • Converts a string to lowercase according to the host’s current locale.
    "HELLO WORLD".toLocaleLowerCase(); // "hello world"
  29. toLocaleUpperCase()

    • Converts a string to uppercase according to the host’s current locale.
    "hello world".toLocaleUpperCase(); // "HELLO WORLD"
  30. valueOf()

    • Returns the primitive value of a String object.
    new String("Hello").valueOf(); // "Hello"
  31. toString()

    • Returns a string representing the object.
    new String("Hello").toString(); // "Hello"
  32. fromCharCode(...codes) (Static Method)

    • Converts Unicode values to characters.
    String.fromCharCode(72, 101, 108, 108, 111); // "Hello"
  33. fromCodePoint(...codePoints) (Static Method)

    • Converts Unicode code points to characters (ES6).
    String.fromCodePoint(134071); // "ð ®·"
  34. raw(template, ...substitutions) (Static Method)

    • Returns the raw string form of a template string (ES6).
    String.raw`Hello\nWorld`; // "Hello\\nWorld"

String Properties

  1. length
    • Returns the length of a string.
    "Hello".length; // 5

This list covers the most common string functions and properties available in JavaScript, allowing for a variety of string manipulations.