JavaScript String Methods and Properties

Method: String Length

Returns the length of a string.

var str = "Hello, World!";
var length = str.length;

Method: String Concatenation

Combines two or more strings.

var str1 = "Hello,";
var str2 = " World!";
var result = str1.concat(str2);

Method: String to Uppercase

Converts a string to uppercase.

var str = "Hello, World!";
var upperCaseStr = str.toUpperCase();

Method: String to Lowercase

Converts a string to lowercase.

var str = "Hello, World!";
var lowerCaseStr = str.toLowerCase();

Method: String Substring

Extracts part of a string between two specified indices.

var str = "Hello, World!";
var subStr = str.substring(0, 5);

Property: String Index Of

Returns the position of the first occurrence of a specified substring in a string.

var str = "Hello, World!";
var position = str.indexOf("World");

Method: String Replace

Replaces a specified substring with another string in a string.

var str = "Hello, World!";
var newStr = str.replace("World", "Universe");

Property: String Trim

Removes whitespace from both ends of a string.

var str = " Hello, World! " ;
var trimmedStr = str.trim();