JavaScript String toLocaleLowerCase() method

The JavaScript string toLocaleLowerCase() method transforms the given string into a lowercase letter on the basis of the current locale of the host. Note: A string can be converted into lowercase letters with the toLowerCase() method but the result may vary according to locale or language. To overcome this problem we have to use toLocaleLowerCase(). … Read more

JavaScript String toLowerCase() method

The JavaScript string toLowerCase() method transforms the whole string into lowercase letter. Original string will not be modified. Syntax: string.toLowerCase() Return: String with lowercase letters. Example: <!DOCTYPE html> <html> <body> <script> var a =”HELLO WORLD!”; document.write(a.toLowerCase()); </script> </body> </html>

JavaScript String slice() method

The JavaScript string slice() method retrieves a part of the given string on the basis of the specified index. It is similar to substring, the only difference is that it supports the negative index. In the case of the negative index, it starts retrieving the sub-string from the end of the string. Syntax: string.slice(start_index, end_index) … Read more

JavaScript String substring() method

The JavaScript string substring() method retrieves the part of the given string on the basis of the specified index. The original string will not be modified. It is similar to slice, the only difference is that it does not support the negative index. Note: It returns the complete string if we do not pass any … Read more

JavaScript String substr() method

The JavaScript string substr() method retrieves the part of the given string on the basis of the specified starting position and length. The original string will not be modified. Syntax: string.substr(position, length) Parameters: position: It represents the position of the string from where the string retrieves starts. length: It represents the number of characters to … Read more

JavaScript String replace() method

The JavaScript string replace() method eliminates a given string with the specified replacement. By default, it will replace the first match only. To replace all matches we have to use a global identifier. Syntax: string.replace(string1, string2) Parameters: string1: It represents the string to be searched and replaced. string2: It represents the new string that will … Read more

JavaScript String match() method

The JavaScript string match() method determines a specified regular expression in a given string and returns that regular expression if a match occurs. Note: To get all the matches we have to use a global modifier. Syntax: string.match(regexp) Parameters: regexp: It represents the regular expression to be searched. Return: Matched regular expression. Example: <!DOCTYPE html> … Read more

JavaScript String search() method

The JavaScript string search() method determines a specified regular expression in a given string and returns its position if a match occurs. Syntax: string.search(regexp) Parameters: regexp: It represents the regular expression to be searched. Return: It will return the position of the regular expression if it is present in the string otherwise returns -1. Example: … Read more

JavaScript String lastIndexOf() method

The JavaScript string lastIndexOf() method retrieves the position of a char value present in the given string from the last position. Note: It is similar to indexOf(). The only difference is that lastIndexOf() returns the last index of a match instead of the first. Syntax 1: string.lastIndexOf(char) Syntax 2: string.lastIndexOf(ch,index) Syntax 3: string.lastIndexOf(str) Syntax 4: … Read more

JavaScript String indexOf() method

The JavaScript string indexOf() method retrieves the position of a char value present in the given string. It is case-sensitive. Syntax 1: string.indexOf(char) Syntax 2: string.indexOf(ch,index) Syntax 3: string.indexOf(str) Syntax 4: string.indexOf(str,index) Parameters: char: It represents the specified char like “c”. str: It represents the specified string like “w3schools”. index: It represents the specified position … Read more