JavaScript String Method

Sakibur Rahaman
4 min readMay 5, 2021

Are you recap your JavaScript string method ? I explain some most used JavaScript string method that used everyday in our programming life.

String 🤗

String is JavaScript primitive data type which contain any text and number . Its a sequence of characters, numbers, special characters and arithmetic values. String must be created by closing single quotes ( ‘ ’ ) or double quotes (“ ”).

The length property returns length of the string.

JavaScript String Methods

chartAt(): JavaScript chartAt() method used to find a char value in a specific index in a string. The string index start from 0 to string.length - 1. the index value can’t be negative or floating value, Index value must be contain integer value. example:

concat(): The JavaScript concat() method joined two or more string and returns a new strings. The method doesn’t affect on previous string create a new string.

includes(): The JavaScript includes() is a case sensitive method determine whether a string contains the characters of a specified string. If the string contain the character the string return true value otherwise return false value.

indexOf(): The JavaScript indexOf() method used to search the position and find the index number of a specific character or string in the given string. The index start from 0 and its also a case sensitive method. If an element not present in the given string, it returns -1.

lastIndexOf(): The JavaScript lastIndexOf() method used to search the position and find the index number of a specific character or string in the given string. It similar to indexOf() method with a difference that it start searching an element from the last position of the string. If an element not present in the given string, it returns -1.

replace(): The JavaScript string replace() method is used to replace a part of a given string with a new substring. This method searches for specified regular expression in a given string and then replace it if the match occurs.

slice(): The JavaScript slice() method is used to fetch the part of the string and returns the new string. It required to specify the index number as the start and end parameters to fetch the part of the string. The index starts from 0.

split(): The JavaScript string split() method is used to splits a string into substring array, then returns that newly created array.

toUpperCase(): The JavaScript toUpperCase() method is used to convert the string into uppercase letter. This method doesn’t make any change in the original string.

toLowerCase(): The JavaScript toLowerCase() method is used to convert the string into lowercase letter. This method doesn’t make any change in the original string.

Thank you For Reading🤩 and connect with me in linkedin.

--

--