The following tables describe the objects available in the JavaScript core language and their methods and properties.
The ActiveXObject object represents an ActiveX object when accessed from within Jscript code. Introduced in Jscript 3.0, it's not available in ECMAScript or Netscape JavaScript. Created with the ActiveXObject constructor; for example, to create a Microsoft Word document, we would write
var objActiveX = new ActiveXObject("Word.Document");
The properties and methods of this object will be those of the ActiveX object thus created. For example, the following code opens a Word document and writes some text to it and to the HTML page.
var objActiveX = new ActiveXObject("Word.Document"); strText="This is being written both to the HTML page and to the Word document."; objActiveX.application.selection.typeText(strText); document.write(strText);
The Array object represents an array of variables. It was introduced in JavaScript 1.1 and Jscript 2.0. An Array object is created with the Array constructor.
var objArray = new Array(10) // an array of 11 elements var objArray = new Array("1", "2", "4") // an array of 3 elements
Property |
Introduced |
Description |
---|---|---|
constructor |
JavaScript 1.1 Jscript 2.0 |
Used to reference the constructor function for the object. |
index |
JavaScript 1.2 |
Not in ECMA-262. The zero-based index indicating the position in the string that matches a regular expression. Not supported by Internet Explorer. |
input |
JavaScript 1.2 |
Not in ECMA-262. Returns the string against which a regular expression was matched. Not supported by Internet Explorer. |
length |
JavaScript 1.1 Jscript 2.0 |
Returns the number of elements in the array. |
prototype |
JavaScript 1.1 Jscript 2.0 |
Returns the prototype for the object, which can be used to extend the object's interface. |
Introduced |
Description |
|
---|---|---|
concat() |
JavaScript 1.2 Jscript 3.0 |
Not in ECMA-262. Concatenates two arrays and returns the new array thus formed. |
eval |
JavaScript 1.1 JavaScript 1.2 (Deprecated) JavaScript 1.3 (Deprecated) |
Deprecated. Evaluates JavaScript code within a specified object. |
join() |
JavaScript 1.1 Jscript 2.0 |
Joins all the elements of an array into a single string. |
pop() |
JavaScript 1.2 |
Not in ECMA-262. Pops the last element from the end of the array and returns that element. Not supported by Internet Explorer. |
push() |
JavaScript 1.2 |
Not in ECMA-262. Pushes one or more elements onto the end of the array and returns the new length of the array. (In JavaScript 1.2, the last element rather than the new length is returned.) Not supported by Internet Explorer. |
reverse() |
JavaScript 1.1 Jscript 2.0 |
Reverses the order of the elements in the array, so that the first element becomes the last and the last becomes the first. |
shift() |
JavaScript 1.2 |
Not in ECMA-262. Removes the first element from the beginning of the array and returns that element. Not supported by Internet Explorer. |
slice() |
JavaScript 1.2 Jscript 3.0 |
Not in ECMA-262. Returns a subarray from the array. |
sort() |
JavaScript 1.1 Jscript 2.0 |
Sorts the elements of the array. |
splice() |
JavaScript 1.2 |
Not in ECMA-262. Adds, removes, or replaces elements in the array. Not supported by Internet Explorer. |
toSource() |
JavaScript 1.3 |
Not in ECMA-262. Returns a string containing the source code for the Array object. Not supported by Internet Explorer. |
toString() |
JavaScript 1.1 Jscript 2.0 |
Converts the Array object into a string. |
unshift() |
JavaScript 1.2 |
Not in ECMA-262. Adds elements to the beginning of the array and returns the new length. Not supported by Internet Explorer. |
Unwatch |
JavaScript 1.2 |
Removes a watchpoint from an object's property. |
valueOf() |
JavaScript 1.1 Jscript 2.0 |
Returns the primitive value of the array. |
Watch |
JavaScript 1.2 |
Adds a watchpoint to an object's property. |
In Netscape JavaScript, this object also inherits the methods watch() and unwatch() from the Object object (not ECMAScript or IE).
The Boolean object is used as a wrapper for a Boolean value. It was introduced in JavaScript 1.1 and Jscript 2.0. It is created with the Boolean constructor, which takes as a parameter the initial value for the object (if this is not a Boolean value, it will be converted into one).
Property |
Introduced |
Description |
---|---|---|
constructor |
JavaScript 1.1 Jscript 2.0 |
Specifies the function that creates an object's prototype. |
prototype |
JavaScript 1.1 Jscript 2.0 |
Returns the prototype for the object, which can be used to extend the object's interface. |
Method |
Introduced |
Description |
---|---|---|
toSource() |
JavaScript 1.3 |
Not in ECMA-262. Returns a string containing the source code for the Boolean object. Not supported by Internet Explorer. |
toString() |
JavaScript 1.1 Jscript 2.0 |
Converts the Boolean object into a string. |
valueOf() |
JavaScript 1.1 Jscript 2.0 |
Returns the primitive value of the Boolean object. |
In Netscape JavaScript, this object also inherits the methods watch() and unwatch() from the Object object (not ECMAScript or IE).
The Date object is used to represent a given date-time. It was introduced in JavaScript 1.0 and Jscript 1.0.
Property |
Introduced |
Description |
---|---|---|
constructor |
JavaScript 1.1 Jscript 2.0 |
Used to reference the constructor function for the object. |
prototype |
JavaScript 1.1 Jscript 2.0 |
Returns the prototype for the object, which can be used to extend the object's interface. |
Introduced |
Description |
|
---|---|---|
getDate() |
JavaScript 1.0 Jscript 1.0 |
Retrieves the date in the month from the Date object. |
getDay() |
JavaScript 1.0 Jscript 1.0 |
Retrieves the day of the week from the Date object. |
getFullYear() |
JavaScript 1.3 Jscript 3.0 |
Retrieves the full year from the Date object. |
getHours() |
JavaScript 1.0 Jscript 1.0 |
Retrieves the hour of the day from the Date object. |
getMilliseconds() |
JavaScript 1.3 Jscript 3.0 |
Retrieves the number of milliseconds from the Date object. |
getMinutes() |
JavaScript 1.0 Jscript 1.0 |
Retrieves the number of minutes from the Date object. |
getMonth() |
JavaScript 1.0 Jscript 1.0 |
Retrieves the month from the Date object. |
getSeconds() |
JavaScript 1.0 Jscript 1.0 |
Retrieves the number of seconds from the Date object. |
getTime() |
JavaScript 1.0 Jscript 1.0 |
Retrieves the number of milliseconds since January 1 1970 00:00:00 from the Date object. |
getTimezoneOffset() |
JavaScript 1.0 Jscript 1.0 |
Retrieves the difference in minutes between the local time zone and UTC. |
getUTCDate() |
JavaScript 1.3 Jscript 3.0 |
Retrieves the date in the month from the Date object adjusted to universal time. |
getUTCDay() |
JavaScript 1.3 Jscript 3.0 |
Retrieves the day of the week from the Date object adjusted to universal time. |
getUTCFullYear() |
JavaScript 1.3 Jscript 3.0 |
Retrieves the year from the Date object adjusted to universal time. |
getUTCHours() |
JavaScript 1.3 Jscript 3.0 |
Retrieves the hour of the day from the Date object adjusted to universal time. |
getUTCMilliseconds() |
JavaScript 1.3 Jscript 3.0 |
Retrieves the number of milliseconds from the Date object adjusted to universal time. |
getUTCMinutes() |
JavaScript 1.3 Jscript 3.0 |
Retrieves the number of minutes from the Date object adjusted to universal time. |
getUTCMonth() |
JavaScript 1.3 Jscript 3.0 |
Retrieves the month from the Date object adjusted to universal time. |
getUTCSeconds() |
JavaScript 1.3 Jscript 3.0 |
Retrieves the number of seconds from the Date object adjusted to universal time. |
getVarDate() |
Jscript 3.0 |
Not in ECMA-262 or Netscape JavaScript. Returns the date in VT_DATE format (used for communicating with ActiveX objects). |
getYear() |
JavaScript 1.0 Jscript 1.0 |
Retrieves the year from the Date object. |
parse() |
JavaScript 1.0 Jscript 1.0 |
Retrieves the number of milliseconds in a date since January 1 1970 00:00:00, local time. |
setDate() |
JavaScript 1.0 Jscript 1.0 |
Sets the date in the month for the Date object. |
setFullYear() |
JavaScript 1.3 Jscript 3.0 |
Sets the full year for the Date object. |
setHours() |
JavaScript 1.0 Jscript 1.0 |
Sets the hour of the day for the Date object. |
setMilliseconds() |
JavaScript 1.3 Jscript 3.0 |
Sets the number of milliseconds for the Date object. |
setMinutes() |
JavaScript 1.0 Jscript 1.0 |
Sets the number of minutes for the Date object. |
setMonth() |
JavaScript 1.0 Jscript 1.0 |
Sets the month for the Date object. |
setSeconds() |
JavaScript 1.0 Jscript 1.0 |
Sets the number of seconds for the Date object. |
setTime() |
JavaScript 1.0 Jscript 1.0 |
Sets the time for the Date object according to the number of milliseconds since January 1 1970 00:00:00. |
setUTCDate() |
JavaScript 1.3 Jscript 3.0 |
Sets the date in the month for the Date object according to universal time. |
setUTCFullYear() |
JavaScript 1.3 Jscript 3.0 |
Sets the full year for the Date object according to universal time. |
setUTCHours() |
JavaScript 1.3 Jscript 3.0 |
Sets the hour of the day for the Date object according to universal time. |
setUTCMilliseconds() |
JavaScript 1.3 Jscript 3.0 |
Sets the number of milliseconds for the Date object according to universal time. |
setUTCMinutes() |
JavaScript 1.3 Jscript 3.0 |
Sets the number of minutes for the Date object according to universal time. |
setUTCMonth() |
JavaScript 1.3 Jscript 3.0 |
Sets the month for the Date object according to universal time. |
setUTCSeconds() |
JavaScript 1.3 Jscript 3.0 |
Sets the number of seconds for the Date object according to universal time. |
setYear() |
JavaScript 1.0 Jscript 1.0 |
Sets the year for the Date object. |
toGMTString() |
JavaScript 1.0 Jscript 1.0 |
Converts the Date object to a string according to Greenwich Mean Time. Replaced by toUTCString. |
toLocaleString() |
JavaScript 1.0 Jscript 1.0 |
Converts the Date object to a string according to the local time zone. |
toSource() |
JavaScript 1.3 |
Returns a string containing the source code for the Date object. |
toString() |
JavaScript 1.1 |
Converts the Date object into a string. |
toUTCString() |
JavaScript 1.3 |
Not in ECMA-262. Converts the Date object to a string according to universal time. Not supported by Internet Explorer. |
UTC() |
JavaScript 1.0 Jscript 1.0 |
Retrieves the number of milliseconds in a date since January 1 1970 00:00:00, universal time. |
valueOf() |
JavaScript 1.1 Jscript 2.0 |
Returns the primitive value of the Date object. |
In Netscape JavaScript, this object also inherits the methods watch() and unwatch() from the Object object (not ECMAScript or IE).
The Enumerator object allows us to iterate through the items in a collection. Introduced in Jscript 3.0; not ECMAScript or Netscape JavaScript. It is created through the Enumerator constructor; the collection to be enumerated is passed in as a parameter.
Method |
Introduced |
Description |
---|---|---|
AtEnd() |
Jscript 3.0 |
Returns true if the Enumerator is at the end of the collection. |
Item() |
Jscript 3.0 |
Returns the item at the current position in the collection. |
MoveFirst() |
Jscript 3.0 |
Moves to the first item in the collection. |
MoveNext() |
Jscript 3.0 |
Moves to the next item in the collection. |
Represents a block of JavaScript code that is to be compiled as a function. Introduced in JavaScript 1.1 and Jscript 2.0. A Function object is created with the Function constructor.
Property |
Introduced |
Description |
---|---|---|
arguments |
JavaScript 1.1 Jscript 2.0 |
An array containing the parameters passed into the function (replaced in Netscape JavaScript by arguments as a local variable within the Function object). |
arguments.callee |
JavaScript 1.2 |
Returns the body of the current Function object (replaced by the callee property of the arguments local variable). Not supported by Internet Explorer. |
arguments.caller |
JavaScript 1.1 |
Not in ECMA-262. Returns the name of the function that called the current Function object (replaced by the caller property of the arguments local variable). Not supported by Internet Explorer. |
arguments.length |
JavaScript 1.1 Jscript 2.0 |
Returns the number of parameters passed into the function (replaced in Netscape JavaScript by the length property of the arguments local variable). |
arity |
JavaScript 1.2 |
Not in ECMA-262. Returns the number of parameters expected by the function. Replaced by the length property. Not supported by Internet Explorer. |
caller |
Jscript 2.0 |
Not in ECMA-262 or Netscape JavaScript. Returns a reference to the function that called the current Function object. |
constructor |
JavaScript 1.1 Jscript 2.0 |
Used to reference the constructor function for the object. |
length |
JavaScript 1.1 |
Returns the number of parameters expected by the function. This differs from arguments.length, which returns the number of parameters actually passed into the function. Not supported by Internet Explorer. |
prototype |
JavaScript 1.1 Jscript 2.0 |
Returns the prototype for the object, which can be used to extend the object's interface. |
Method |
Introduced |
Description |
---|---|---|
apply() |
JavaScript 1.3 |
Not in ECMA-262. Applies a method of one object in the context of the object that calls the method. Not supported by Internet Explorer. |
call() |
JavaScript 1.3 |
Not in ECMA-262. Executes a method of one object in the context of the object that calls the method. Not supported by Internet Explorer. |
toSource() |
JavaScript 1.3 |
Not in ECMA-262. Returns a string containing the source code for the Function object. Not supported by Internet Explorer. |
toString() |
JavaScript 1.1 Jscript 2.0 |
Converts the Function object into a string. |
valueOf() |
JavaScript 1.1 Jscript 2.0 |
Returns the primitive value of the Function |
This is merely a synonym for Packages.java. Introduced in JavaScript 1.1, but not supported by ECMAScript or Internet Explorer.
Represents a Java array accessed from within JavaScript. Introduced in JavaScript 1.1; not supported by ECMAScript or Internet Explorer. Created by Java methods that return an array.
Property |
Introduced |
Description |
---|---|---|
length |
JavaScript 1.1 |
Not in ECMA-262. |
The number of elements in the Java array.
Method |
Introduced |
Description |
---|---|---|
toString() |
JavaScript 1.1 |
Not in ECMA-262. |
In JavaScript 1.4, this method is overridden by the toString method of the java.lang.Object superclass.
In earlier versions, this method returns a string, which identifies the object as a JavaArray.
In JavaScript 1.4, the JavaArray object also inherits methods from the Java array superclass java.lang.Object.
Used to reference a Java class from within JavaScript. Introduced in JavaScript 1.1; not supported by ECMAScript or Internet Explorer.
The properties of a JavaClass object are the static fields of the Java class.
Represents a Java object accessed from within JavaScript code. Introduced in JavaScript 1.1, it is not supported by ECMAScript or Internet Explorer. Created by any Java method that returns an object, or using the new keyword with the Packages object.
Inherits the public properties of the Java class of which it is an instance. It also inherits the properties of any superclass of which the Java class is a member.
Inherits the public methods of the Java class of which it is an instance. It also inherits methods from java.lang.Object and from any other superclass of which the Java class is a member.
Represents a Java package when accessed from within JavaScript code. Introduced in JavaScript 1.1, it is not supported by ECMAScript or Internet Explorer. Created through the Packages object.
The properties of a JavaPackage are the JavaClass and JavaPackage objects that it contains.
The Math object provides methods and properties used for mathematical calculations. Introduced in JavaScript 1.0 and Jscript 1.0. The Math object is a top-level object, which can be accessed without a constructor.
Property |
Introduced |
Description |
---|---|---|
E |
JavaScript 1.0 Jscript 1.0 |
Returns Euler's constant (the base of natural logarithms) (approximately 2.718). |
LN10 |
JavaScript 1.0 Jscript 1.0 |
Returns the natural logarithm of 10 (approximately 2.302). |
LN2 |
JavaScript 1.0 Jscript 1.0 |
Returns the natural logarithm of 2 (approximately 0.693). |
LOG10E |
JavaScript 1.0 Jscript 1.0 |
Returns the base 10 logarithm of E (approximately 0.434). |
LOG2E |
JavaScript 1.0 Jscript 1.0 |
Returns the base 2 logarithm of E (approximately 1.442). |
PI |
JavaScript 1.0 Jscript 1.0 |
Returns pi, the ratio of the circumference of a circle to its diameter (approximately 3.142). |
SQRT1_2 |
JavaScript 1.0 Jscript 1.0 |
Returns the square root of 1/2 (approximately 0.707). |
SQRT2 |
JavaScript 1.0 Jscript 1.0 |
Returns the square root of 2 (approximately 1.414). |
Introduced |
Description |
|
---|---|---|
abs() |
JavaScript 1.0 Jscript 1.0 |
Returns the absolute (positive) value of a number. |
acos() |
JavaScript 1.0 Jscript 1.0 |
Returns the arccosine of a number (in radians). |
asin() |
JavaScript 1.0 Jscript 1.0 |
Returns the arcsine of a number (in radians). |
atan() |
JavaScript 1.0 Jscript 1.0 |
Returns the arctangent of a number (in radians). |
atan2() |
JavaScript 1.0 Jscript 2.0 |
Returns the angle (in radians) between the x-axis and the position represented by the y and x coordinates passed in as parameters. |
ceil() |
JavaScript 1.0 Jscript 1.0 |
Returns the value of a number rounded up to the nearest integer. |
cos() |
JavaScript 1.0 Jscript 1.0 |
Returns the cosine of a number. |
exp() |
JavaScript 1.0 Jscript 1.0 |
Returns E to the power of the argument passed in. |
floor() |
JavaScript 1.0 Jscript 1.0 |
Returns the value of a number rounded down to the nearest integer. |
log() |
JavaScript 1.0 Jscript 1.0 |
Returns the natural logarithm (base E) of a number. |
max() |
JavaScript 1.0 Jscript 1.0 |
Returns the greater of two numbers passed in as parameters. |
min() |
JavaScript 1.0 Jscript 1.0 |
Returns the lesser of two numbers passed in as parameters. |
pow() |
JavaScript 1.0 Jscript 1.0 |
Returns the first parameter raised to the power of the second. |
random() |
JavaScript 1.0 (Unix only), 1.1 Jscript 1.0 |
Returns a pseudo-random number between 0 and 1. |
round() |
JavaScript 1.0 Jscript 1.0 |
Returns the value of a number rounded up or down to the nearest integer. |
sin() |
JavaScript 1.0 Jscript 1.0 |
Returns the sine of a number. |
sqrt() |
JavaScript 1.0 Jscript 1.0 |
Returns the square root of a number. |
tan() |
JavaScript 1.0 Jscript 1.0 |
Returns the tangent of a number. |
In Netscape JavaScript, this object also inherits the methods watch() and unwatch() from the Object object (not ECMAScript or IE).
This is merely a synonym for Packages.netscape. Introduced in JavaScript 1.1, it is not available in ECMAScript or Internet Explorer.
The Number object acts as a wrapper for primitive numeric values. Introduced in JavaScript 1.1 and Jscript 2.0. A Number object is created using the Number constructor with the initial value for the number passed in as a parameter.
Property |
Introduced |
Description |
---|---|---|
constructor |
JavaScript 1.1 Jscript 2.0 |
Used to reference the constructor function for the object. |
MAX_VALUE |
JavaScript 1.1 Jscript 2.0 |
Returns the largest number that can be represented in JavaScript (approximately 1.79E+308). |
MIN_VALUE |
JavaScript 1.1 Jscript 2.0 |
Returns the smallest number that can be represented in JavaScript (5E-324). |
NaN |
JavaScript 1.1 Jscript 2.0 |
Returns a value that is "not a number". |
NEGATIVE_INFINITY |
JavaScript 1.1 Jscript 2.0 |
Returns a value representing negative infinity. |
POSITIVE_INFINITY |
JavaScript 1.1 Jscript 2.0 |
Returns a value representing (positive) infinity. |
prototype |
JavaScript 1.1 Jscript 2.0 |
Returns the prototype for the object, which can be used to extend the object's interface. |
Method |
Introduced |
Description |
---|---|---|
toSource() |
JavaScript 1.3 |
Not in ECMA-262. Returns a string containing the source code for the Number object. Not supported by Internet Explorer. |
toString() |
JavaScript 1.1 Jscript 2.0 |
Converts the Number object into a string. |
valueOf() |
JavaScript 1.1 Jscript 2.0 |
Returns the primitive value of the Number object. |
In Netscape JavaScript, this object also inherits the methods watch and unwatch from the Object object (not ECMAScript or IE).
Object is the primitive type for JavaScript objects, from which all other objects are descended (that is, all other objects inherit the methods and properties of the Object object). Introduced in JavaScript 1.0 and Jscript 3.0. An Object object is created using the Object constructor.
Property |
Introduced |
Description |
---|---|---|
constructor |
JavaScript 1.1 Jscript 3.0 |
Used to reference the constructor function for the object. |
prototype |
JavaScript 1.1 Jscript 3.0 |
Returns the prototype for the object, which can be used to extend the object's interface. |
Introduced |
Description |
|
---|---|---|
eval() |
JavaScript 1.0 |
Not in ECMA-262. Evaluates a string of JavaScript code in the context of the specified object. Not supported in Internet Explorer and no longer available in Netscape JavaScript: replaced by the top-level eval function. |
toSource() |
JavaScript 1.3 |
Returns a string containing the source code for the Object object. Not supported by Internet Explorer. |
toString() |
JavaScript 1.0 Jscript 3.0 |
Converts the Object object into a string. |
unwatch() |
JavaScript 1.2 |
Not in ECMA-262. Removes from the object's property a watchpoint that was added with the watch method. Not supported by Internet Explorer. |
valueOf() |
JavaScript 1.1 Jscript 3.0 |
Returns the primitive value of the Object object. |
watch() |
JavaScript 1.2 |
Not in ECMA-262. |
Allows us to add a watch-point to a property of the object. Not supported by Internet Explorer.
Allows access to Java packages from within JavaScript code. Introduced in JavaScript 1.1, it is not supported by ECMAScript or Internet Explorer. This is a top-level object, which does not need to be created with a constructor. The Packages object takes as its properties the Java package that is to be accessed.
The RegExp object is used to contain the pattern for a regular expression. Introduced in JavaScript 1.2 and Jscript 3.0, it is not supported by ECMAScript. RegExp objects can be created in two ways: with the RegExp constructor, or using a text literal.
Some of these properties have both long and short names. The short names are derived from the Perl programming language.
Property |
Introduced |
Description |
---|---|---|
$1, $2, ... $9 |
JavaScript 1.2 Jscript 3.0 |
Not in ECMA-262. Matches placed in parentheses and remembered. Not supported by Internet Explorer. |
$_ |
JavaScript 1.2 Jscript 3.0 |
See input. |
$* |
JavaScript 1.2 |
See multiline. |
$& |
JavaScript 1.2 |
See lastMatch. |
$+ |
JavaScript 1.2 |
See lastParen. |
$` |
JavaScript 1.2 |
See leftContext. |
$' |
JavaScript 1.2 |
See rightContext. |
constructor |
JavaScript 1.2 Jscript 3.0 |
Used to reference the constructor function for the object. |
global |
JavaScript 1.2 |
Not in ECMA-262. Indicates whether all possible matches in the string are to be made, or only the first. Corresponds to the g flag. Not supported by Internet Explorer. |
ignoreCase |
JavaScript 1.2 |
Not in ECMA-262. Indicates whether the match is to be case- insensitive. Corresponds to the i flag. Not supported by Internet Explorer. |
index |
Jscript 3.0 |
Not in ECMA-262 or Netscape JavaScript. The position of the first match in the string. |
input |
JavaScript 1.2 Jscript 3.0 |
Not in ECMA-262. The string against which the regular expression is matched. |
lastIndex |
JavaScript 1.2 Jscript 3.0 |
Not in ECMA-262. The position in the string from which the next match is to be started. |
lastMatch |
JavaScript 1.2 |
Not in ECMA-262. The last characters to be matched. Not supported by Internet Explorer. |
lastParen |
JavaScript 1.2 |
Not in ECMA-262. The last match placed in parentheses and remembered (if any occurred). Not supported by Internet Explorer. |
leftContext |
JavaScript 1.2 |
Not in ECMA-262. The substring preceding the most recent match. Not supported by Internet Explorer. |
multiline |
JavaScript 1.2 |
Not in ECMA-262. Indicates whether strings are to be searched across multiple lines. Not supported by Internet Explorer. |
prototype |
JavaScript 1.2 Jscript 3.0 |
Returns the prototype for the object, which can be used to extend the object's interface. |
rightContext |
JavaScript 1.2 |
Not in ECMA-262. The substring following the most recent match. Not supported by Internet Explorer. |
source |
JavaScript 1.2 Jscript 3.0 |
Not in ECMA-262. |
The text of the pattern for the regular expression.
Method |
Introduced |
Description |
---|---|---|
compile() |
JavaScript 1.2 Jscript 3.0 |
Not in ECMA-262. Compiles the RegExp object. |
exec() |
JavaScript 1.2 Jscript 3.0 |
Not in ECMA-262. Executes a search for a match in the string parameter passed in. |
test() |
JavaScript 1.2 Jscript 3.0 |
Not in ECMA-262. Tests for a match in the string parameter passed in. |
toSource() |
JavaScript 1.3 |
Not in ECMA-262. Returns a string containing the source code for the RegExp object. Not supported by Internet Explorer. |
toString() |
JavaScript 1.2 Jscript 3.0 |
Converts the RegExp object into a string. |
valueOf() |
JavaScript 1.2 Jscript 3.0 |
Returns the primitive value of the RegExp object. |
In Netscape JavaScript, this object also inherits the methods watch() and unwatch() from the Object object (not ECMAScript or IE).
The following table lists the special characters that may be used in regular expressions.
Character |
Examples |
Function |
---|---|---|
\ |
/n/ matches n /\n/ matches a linefeed character /^/ matches the start of a line /\^/ matches ^ |
For characters that are by default treated as normal characters, the backslash indicates that the next character is to be interpreted with a special value. For characters that are usually treated as special characters, the backslash indicates that the next character is to be interpreted as a normal character. |
^ |
/^A/ matches the first but not the second A in "A man called Adam" |
Matches the start of a line or of the input. |
$ |
/r$/ matches only the last r in "horror" |
Matches the end of a line or of the input. |
* |
/ro*/ matches r in "right", ro in "wrong" and "roo" in "room" |
Matches the preceding character zero or more times. |
+ |
/l+/ matches l in "life", ll in "still" and lll in "stilllife" |
Matches the preceding character once or more. For example, /a+/ matches the 'a' in "candy" and all the a's in "caaaaaaandy." |
? |
/Smythe?/ matches "Smyth" and "Smythe" |
Matches the preceding character once or zero times. |
. |
/.b/ matches the second but not the first b in "blob" |
Matches any character apart from the newline character. |
(x) |
/(Smythe?)/ matches "Smyth" and "Smythe" in "John Smyth and Rob Smythe" and allows the substrings to be retrieved as RegExp.$1 and RegExp.$2 respectively. |
Matches x and remembers the match. The matched substring can be retrieved from the elements of the array that results from the match, or from the RegExp object's properties $1, $2 ... $9 or lastParen. |
x|y |
/Smith|Smythe/ matches "Smith" and "Smythe" |
Matches either x or y (where x and y are blocks of characters). |
{n} |
/l{2}/ matches ll in "still" and the first two ls in "stilllife" |
Matches exactly n instances of the preceding character (where n is a positive integer). |
{n,} |
/l{2,}/ matches ll in "still" and lll in "stilllife" |
Matches n or more instances of the preceding character (where n is a positive integer). |
{n,m} |
/l{1,2}/ matches l in "life", ll in "still" and the first two ls in "stilllife" |
Matches between n and m instances of the preceding character (where n and m are positive integers). |
[xyz] |
[ab] matches a and b [a-c] matches a, b and c |
Matches any one of the characters in the square brackets. A range of characters in the alphabet can be matched using a hyphen. |
[^xyz] |
[^aeiouy] matches s in "easy" [^a-y] matches z in "lazy" |
Matches any character except for those enclosed in the square brackets. A range of characters in the alphabet can be specified using a hyphen. |
[\b] |
Matches a backspace. |
|
\b |
/t\b/ matches the first t in "about time" |
Matches a word boundary (for example, a space or the end of a line). |
\B |
/t\Bi/ matches ti in "it is time" |
Matches when there is no word boundary in this position. |
\cX |
/\cA/ matches ctrl-A |
Matches a control character. |
\d |
/IE\d/ matches IE4, IE5, etc. |
Matches a digit character. This is identical to [0-9]. |
\D |
/\D/ matches the decimal point in "3.142" |
Matches any character that is not a digit. This is identical to [^0-9]. |
\f |
Matches a form-feed character. |
|
\n |
Matches a line-feed character. |
|
\r |
Matches a carriage return character. |
|
\s |
/\s/ matches the space in "not now" |
Matches any white space character, including space, tab, line-feed, etc. This is identical to [ \f\n\r\t\v]. |
\S |
/\S/ matches a in " a " |
Matches any character other than a white space character. This is identical to [^ \f\n\r\t\v]. |
\t |
Matches a tab character. |
|
\v |
Matches a vertical tab character. |
|
\w |
/\w/ matches O in "O?!" and 1 in "$1" |
Matches any alphanumeric character or the underscore. This is identical to [A-Za-z0-9_]. |
\W |
/\W/ matches $ in "$10million" and @ in "j_smith@wrox" |
Matches any non-alphanumeric character (excluding the underscore). This is identical to [^A-Za-z0-9_]. |
\n |
/(Joh?n) and \1/ matches John and John in "John and John's friend" but does not match "John and Jon" |
Matches the last substring that matched the nth match placed in parentheses and remembered (where n is a positive integer). |
\octal \xhex |
/\x25/ matches % |
Matches the character corresponding to the specified octal or hexadecimal escape value. |
The String object is used to contain a string of characters. Introduced in JavaScript 1.0 and Jscript 1.0. This must be distinguished from a string literal, but the methods and properties of the String object can also be accessed by a string literal, since a temporary object will be created when they are called.
Property |
Introduced |
Description |
---|---|---|
constructor |
JavaScript 1.1 Jscript 2.0 |
Used to reference the constructor function for the object. |
length |
JavaScript 1.0 Jscript 1.0 |
Returns the number of characters in the string. |
prototype |
JavaScript 1.1 Jscript 2.0 |
Returns the prototype for the object, which can be used to extend the object's interface. |
Introduced |
Description |
|
---|---|---|
anchor() |
JavaScript 1.0 Jscript 1.0 |
Not in ECMA-262. Returns an HTML anchor element. This can be used as a target for another link but cannot be used to link to another document or part of a document. |
big() |
JavaScript 1.0 Jscript 1.0 |
Not in ECMA-262. Encloses the string in <BIG>...</BIG> tags. |
blink() |
JavaScript 1.0 Jscript 1.0 |
Not in ECMA-262. Encloses the string in <BLINK>...</BLINK> tags. |
bold() |
JavaScript 1.0 Jscript 1.0 |
Not in ECMA-262. Encloses the string in <B>...</B> tags. |
charAt() |
JavaScript 1.0 Jscript 1.0 |
Returns the character at the specified position in the string. |
charCodeAt() |
JavaScript 1.2 Jscript 3.0 |
Returns the Unicode value of the character at the specified position in the string. |
concat() |
JavaScript 1.2 Jscript 3.0 |
Not in ECMA-262. Concatenates the strings supplied as arguments and returns the string thus formed. |
fixed() |
JavaScript 1.0 Jscript 1.0 |
Not in ECMA-262. Encloses the string in <TT>...</TT> tags. |
fontcolor() |
JavaScript 1.0 Jscript 1.0 |
Not in ECMA-262. Encloses the string in <FONT COLOR=string>...</FONT> tags. |
fontsize() |
JavaScript 1.0 Jscript 1.0 |
Not in ECMA-262. Encloses the string in <FONT SIZE=string>...</FONT> tags. |
fromCharCode() |
JavaScript 1.2 Jscript 3.0 |
Returns the string formed from the concatenation of the characters represented by the supplied Unicode values. |
indexOf() |
JavaScript 1.0 Jscript 1.0 |
Returns the position within the String object of the first match for the supplied substring. Returns -1 if the substring is not found. |
italics() |
JavaScript 1.0 Jscript 1.0 |
Not in ECMA-262. Encloses the string in <I>...</I> tags. |
lastIndexOf() |
JavaScript 1.0 Jscript 1.0 |
Returns the position within the String object of the last match for the supplied substring. Returns -1 if the substring is not found. |
link() |
JavaScript 1.0 Jscript 1.0 |
Not in ECMA-262. Creates an HTML link element that can be used to link to another web page. |
match() |
JavaScript 1.2 Jscript 3.0 |
Not in ECMA-262. Used to match a regular expression against a string. |
replace() |
JavaScript 1.2 Jscript 3.0 |
Not in ECMA-262. Used to replace a substring that matches a regular expression with a new value. |
search() |
JavaScript 1.2 Jscript 3.0 |
Not in ECMA-262. Searches for a match between a regular expression and the string. |
slice() |
JavaScript 1.0 Jscript 3.0 |
Not in ECMA-262. Returns a substring of the String object. |
small() |
JavaScript 1.0 Jscript 1.0 |
Not in ECMA-262. Encloses the string in <SMALL>...</SMALL> tags. |
split() |
JavaScript 1.1 Jscript 3.0 |
Splits a String object into an array of strings by separating the string into substrings. |
strike() |
JavaScript 1.0 Jscript 1.0 |
Not in ECMA-262. Encloses the string in <STRIKE>...</STRIKE> tags. |
sub() |
JavaScript 1.0 Jscript 1.0 |
Not in ECMA-262. Encloses the string in <SUB>...</SUB> tags. |
substr() |
JavaScript 1.0 Jscript 3.0 |
Not in ECMA-262. Returns a substring of the characters from the given starting position and containing the specified number of characters. |
substring() |
JavaScript 1.0 Jscript 1.0 |
Returns a substring of the characters between two positions in the string. |
sup() |
JavaScript 1.0 Jscript 1.0 |
Not in ECMA-262. Encloses the string in <SUP>...</SUP> tags and causes a string to be displayed as superscript. |
toLowerCase() |
JavaScript 1.0 Jscript 1.0 |
Returns the string converted to lower case. |
toSource() |
JavaScript 1.3 |
Not in ECMA-262. Returns a string containing the source code for the String object. Not supported by Internet Explorer. |
toString() |
JavaScript 1.1 Jscript 2.0 |
Converts the String object into a string. |
toUpperCase() |
JavaScript 1.0 Jscript 1.0 |
Returns the string converted to uppercase. |
valueOf() |
JavaScript 1.1 Jscript 2.0 |
Returns the primitive value of the String object. |
In Netscape JavaScript, this object also inherits the methods watch() and unwatch() from the Object object (not ECMAScript or IE).
A synonym for Packages.sun. Introduced in JavaScript 1.1, it is not supported by ECMAScript or Internet Explorer.
The VBArray object represents in Jscript an array created in Visual Basic or VBScript. Introduced in Jscript 3.0, it is not supported by ECMAScript or Netscape JavaScript. A Jscript VBArray object is created with the VBArray constructor, which takes a Visual Basic array as a parameter.
Method |
Introduced |
Description |
---|---|---|
dimensions() |
Jscript 3.0 |
Returns the number of dimensions in the VBArray. |
getItem() |
Jscript 3.0 |
Retrieves the specified element from the VBArray. |
lbound() |
Jscript 3.0 |
Retrieves the index position of the first element in the VBArray. |
toArray() |
Jscript 3.0 |
Converts the VBArray into a normal Jscript array. |
ubound() |
Jscript 3.0 |
Retrieves the index position of the last element in the VBArray. |