String object (Object/core)

An object of the class "String".

Availability:

ECMAScript edition - 2
JavaScript - 1.0
JScript - 1.0
Internet Explorer - 3.02
Netscape - 2.0
Netscape Enterprise server - 2.0
Opera - 3.0
JavaScript syntax:-myString = new String()
-myString = String
Object properties:constructor, length, prototype
Class methods:fromCharCode()
Object methods:anchor(), big(), blink(), bold(), charAt(), charCodeAt(), concat(), fixed(), fontcolor(), fontsize(), fromCharCode(), indexOf(), italics(), lastIndexOf(), link(), localeCompare(), match(), replace(), search(), slice(), small(), split(), strike(), sub(), substr(), substring(), sup(), toLocaleLowerCase(), toLocaleUpperCase(), toLowerCase(), toSource(), toString(), toUpperCase(), valueOf()

An instance of the class "String" is created by using the new operator on the String() constructor. The new object adopts the behavior of the built-in prototype object through the prototype-inheritance mechanisms.

All properties and methods of the prototype are available as if they were part of the instance.

A String object is a member of the type Object.

Cloning the built-in String object creates new String objects. This is done by calling the String constructor with the new operator being applied to an existing String object, thus:

myString = new String("a string of text");

A String object can be coerced to a string value and can be used anywhere where a string value would be expected.

Programmers familiar with object oriented techniques may prefer to use the String object while procedural language programmers may implement the same functionality with a string value instead.

This is an example of the flexibility of JavaScript in its ability to accommodate a variety of users from different backgrounds.

The prototype for the String prototype object is the Object prototype object.

In Netscape Navigator, you can traverse a string as if it were an array and access characters individually by their index position in the array. This doesn't work in MSIE.

See also:Native object, Object object, String concatenate (+), String.Class, String.length, String.prototype, unwatch(), watch()

PropertyJavaScriptJScriptNIEOperaNESECMADOMCSSHTMLNotes
constructor1.0 1.01.0 1.02.0 2.03.02 3.02 n/a n/a2 2 n/a n/a n/a-
length1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.02 2 n/a n/a n/aReadOnly, DontDelete, DontEnum.
prototype1.1 1.13.0 3.03.0 3.04.0 4.03.0 3.03.0 3.02 2 n/a n/a n/a-

MethodJavaScriptJScriptNIEOperaNESECMADOMCSSHTMLNotes
anchor()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.0 n/a n/a n/a n/a-
big()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.0 n/a n/a n/a n/aDeprecated
blink()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.0 n/a n/a n/a n/aDeprecated
bold()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.0 n/a n/a n/a n/aDeprecated
charAt()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.02 2 n/a n/a n/a-
charCodeAt()1.2 1.25.5 5.54.0 4.05.5 5.53.0 3.03.0 3.02 2 n/a n/a n/aWarning
concat()1.2 1.23.0 3.04.0 4.04.0 4.0 n/a3.0 3.03 3 n/a n/a n/a-
fixed()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.0 n/a n/a n/a n/aDeprecated
fontcolor()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.0 n/a n/a n/a n/aDeprecated
fontsize()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.0 n/a n/a n/a n/aDeprecated
fromCharCode()1.2 1.23.0 3.04.0 4.04.0 4.03.0 3.03.0 3.03 3 n/a n/a n/a-
indexOf()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.02 2 n/a n/a n/a-
italics()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.0 n/a n/a n/a n/aDeprecated
lastIndexOf()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.02 2 n/a n/a n/a-
link()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.0 n/a n/a n/a n/a-
localeCompare()1.5 1.55.5 5.56.0 6.05.5 5.5 n/a n/a3 3 n/a n/a n/a-
match()1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a3 3 n/a n/a n/aWarning
replace()1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a3 3 n/a n/a n/aWarning
search()1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a3 3 n/a n/a n/aWarning
slice()1.2 1.23.0 3.04.0 4.04.0 4.0 n/a2.0 2.03 3 n/a n/a n/a-
small()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.0 n/a n/a n/a n/aDeprecated
split()1.1 1.13.0 3.03.0 3.04.0 4.03.0 3.02.0 2.02 2 n/a n/a n/a-
strike()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.0 n/a n/a n/a n/a-
sub()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.0 n/a n/a n/a n/aDeprecated
substr()1.2 1.23.0 3.04.0 4.04.0 4.0 n/a3.0 3.03 3 n/a n/a n/a-
substring()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.02 2 n/a n/a n/a-
sup()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.0 n/a n/a n/a n/aDeprecated
toLocaleLowerCase()1.5 1.55.5 5.56.0 6.05.5 5.53.0 3.02.0 2.03 3 n/a n/a n/a-
toLocaleUpperCase()1.5 1.55.5 5.56.0 6.05.5 5.53.0 3.02.0 2.03 3 n/a n/a n/a-
toLowerCase()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.02 2 n/a n/a n/a-
toSource()1.3 1.33.0 3.04.06 4.064.0 4.0 n/a n/a3 3 n/a n/a n/a-
toString()1.3 1.31.0 1.04.06 4.063.02 3.02 n/a n/a2 2 n/a n/a n/a-
toUpperCase()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.02.0 2.02 2 n/a n/a n/a-
valueOf()1.1 1.13.0 3.03.0 3.04.0 4.0 n/a n/a2 2 n/a n/a n/a-

Cross-references:

ECMA 262 edition 2 - section - 4.3.18

ECMA 262 edition 2 - section - 10.1.5

ECMA 262 edition 2 - section - 15.5

ECMA 262 edition 3 - section - 4.3.18

ECMA 262 edition 3 - section - 15.5

Wrox Instant JavaScript - page - 33