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

concat() JavaScript JS

The JavaScript string concat() method retrieves a combination of two or more strings. Original strings will not be modified. Syntax: string.concat(string1,string2,…) Parameters: string1,string2,…: Represents the different strings to combined. Return: New string after the combination of strings. Example: <!DOCTYPE html> <html> <body> <script> document.writeln(“HELLO”.concat(” WORLD!”)); </script> </body> </html>

JavaScript String charCodeAt() method

The JavaScript string charCodeAt() method retrieves the Unicode value of a character present at the specified index. Index can be from 0 to n-1 where n is the size of the string. It will return an integer value between 0 and 65535. Syntax: string.charCodeAt(index) Parameters: index: It represents the specified position of a character. Return: … Read more

charAt String JavaScript

The JavaScript string charAt() method retrieves the char value present at the specified index. If n is the size of the string then the index can be from 0 to n-1. Syntax: String.charAt(index) Parameters: index: It represents the specified position of a character. Return: Char value present at the specified index. Example 1: <!DOCTYPE html> … Read more

Set values() JavaScript

The JavaScript Set values() method gives an object of Set iterator that contains the values for each element. It is similar to the keys() method of Map. Syntax: setObj.values() Return: Iterator object. Example: <!DOCTYPE html> <html> <body> <script> var jewels = new Set(); jewels.add(“DIAMOND”).add(“GOLD”).add(“PLATINUM”).add(“SILVER”); var gems =jewels.values(); document.writeln(gems.next().value+”<br>”); document.writeln(gems.next().value+”<br>”); document.writeln(gems.next().value+”<br>”); document.writeln(gems.next().value); </script> </body> </html>