The string data type is a primitive data type that represents a sequence of characters.
String object. The
String object essentially wraps the primitive string with methods and properties used to access and manipulate individual characters or the entire string.
String objects can be created by calling the
new String() constructor or the
String() global function:
var string1 = new String([string]);
var string1 = String([string]);
String primitives can be created using the string literal form:
var string2 = 'string';
var string3 = "string";
String objects and string primitives is done automatically, thus the methods of the
String object can be called on string primitives as well.
valueOf method of the
String object can be used to manually convert a
String object to a string primitive.
Individual characters in a string can be accessed by calling the
charAt method with the zero-based index of the desired character:
var name = "Jane Doe"; name.charAt(1); // "a" name.charAt(4); // " "
It's also possible to use the square brackets notation:
name; // "J"
This feature, however, is not supported in all browsers, so it's best to stick with the
concat(string1 [, string2 [, ...]])
fromCharCode(num1 [, num2 [, ...]])
indexOf(searchString [, offset])
lastIndexOf(searchString [, offset])
patternagainst the input string
slice(offset [, length])
split(pattern [, limit])
substr(offset [, length])
substring(indexStart , [indexStop])