Skip to content

Top 13 JavaScript String methods every JS beginner should know!!


    A quick recap of JavaScript Strings:

    A JavaScript string stores a series of characters like “John Doe”. String indexes are zero-based: The first character is in position 0, the second in 1, and so on.

    Strings are used for storing and manipulating text in JavaScript. Strings can be enclosed within either single quotes, double quotes, or backticks. Here’s a simple demonstration of creating Strings.

    ome of the commonly used JavaScript String methods:

    string.length charAt(index)




    slice(start, end)


    substr(start, length)





    padStart() and padEnd()

    1.String Length

    The length property is a read-only property that returns the length of a string. There will be no effect if we try to change it manually.

    his function is used to get the length of string in Java. The string length method returns the number of characters written in the String. This method returns the length of any string which is equal to the number of 16-bit Unicode characters in the string.


    This method provides the char value present at the specified index. The charAt() method takes in the index as a parameter – An integer between 0 and “str.length – 1” and returns the char value at the specified index.
    The charAt() method returns the character at a specified index in a string. The index of the first character is 0, the second character is 1, and so on. The index of the last character in a string is string. length-1, the second last character is string. length-2, and so on (See “More Examples”).


    The concat() method concatenates two or more strings and returns a new string containing the combined text of the strings provided. If the arguments are not of the type string, they are converted to string values before concatenating.


    The JavaScript string replace() method is used to replace a part of a given string with a new substring. Note: The replace() method does not change the string it is called on. It simply returns a new string.


    This string method splits a string into a substring array, then returns that newly created array.
    It takes in 2 parameters – pattern describing where each split should occur and the separator can be a simple string or it can be a regular expression.

    6.slice(start, end)

    The slice() method extracts and returns a part of the string from start to (excluding) the end.
    If there’s no second argument specified, then splice method goes till the end of the string.
    Negative values from start/end is also possible.


    This method is almost similar to slice(). The substring() method returns the part of a string between start and end.
    It takes in 2 parameters: starting index and the ending index.
    Negative arguments are not supported, they’re r=treated as 0.

    8.ubstr(start, length)

    This method takes in two parameters: first one is the starting index and the second parameter specifies the length of the extracted part.


    The toLowerCase() method returns the string converted to lowercase.


    The toUpperCase() method returns the string converted to uppercase.


    The includes() method performs a search to determine whether one string may be found within another string, returning true or false as appropriate.


    The trim() method removes whitespace from both sides of a string.

    String Padding- padStart() and padEnd()

    The padStart() and padEnd() methods support padding at the beginning and at the end of a string.
    It takes in the two-parameter:
    1- targetLength: length of the final string 2- padString: The string to pad the current string with.
    All string methods return a new string. They don’t modify the original string. In other words, Strings are immutable.