< 1, 2, 3, 4, 5, 6, >
Array Object
The Array object is used to store a set of values in a single variable name. Each value is an element of the array and has an associated index number. You create an instance of the Array object with the "new" keyword. The following example creates two arrays, both of three elements:
var family_names=new Array(3)
var family_names=new Array("Tove","Jani","Stale") |
You can refer to a particular element in the array by using the name of the array and the index number. The index number starts at 0. If you create an array with a single numeric parameter, you can assign data to each of the elements in the array like this:
family_names[0]="Tove" family_names[1]="Jani" family_names[2]="Stale" |
And the data can be retrieved by using the index number of the particular array element you want, like this:
mother=family_names[0] father=family_names[1] |
The Array object's properties and methods are described below: NN: Netscape, IE: Internet Explorer
Properties:
Syntax: object.property_name
| Property |
Description |
NN |
IE |
| constructor |
Contains the function that created an object's prototype |
4 |
4 |
| length |
Returns the number of elements in the array |
3 |
4 |
| prototype |
Allows you to add properties to an array |
3 |
4 |
Methods: Syntax: object.method_name()
| Method |
Description |
NN |
IE |
| concat() |
Joins two or more arrays and returns a new array |
4 |
4 |
| join(delimiter) |
Puts all the elements of an array into a string separated by a specified delimiter (comma is default) |
3 |
4 |
| pop() |
Removes and returns the last element of an array |
4 |
5.5 |
| push("element1","element2") |
Adds one or more elements to the end of an array and returns the new length |
4 |
5.5 |
| reverse() |
Reverses the order of the elements in an array |
3 |
4 |
| shift() |
Removes and returns the first element of an array |
4 |
5.5 |
| slice(begin[,end]) |
Creates a new array from a selected section of an existing array |
4 |
4 |
| sort() |
Sorts the elements of an array |
3 |
4 |
| splice(index,howmany[,el1,el2]) |
Adds and/or removes elements of an array |
4 |
5.5 |
| toSource() |
Returns a string that represents the source code of the array |
4.06 |
4 |
| toString() |
Returns a string that represents the specified array and its elements |
3 |
4 |
| unshift("element1","element2") |
Adds one or more elements to the beginning of an array and returns the new length |
4 |
5.5 |
| valueOf() |
Returns the primitive value of an array |
4 |
3 |
Boolean Object
The Boolean object is an object wrapper for a Boolean value and it is used to convert a non-Boolean value to a Boolean value.
Boolean Object
The Boolean object is an object wrapper for a Boolean value and it is used to convert a non-Boolean value to a Boolean value, either true or false. If the Boolean object has no initial value or if it is 0, null, "", false, or NaN, the initial value is false. Otherwise it is true (even with the string "false"). All the following lines of code create Boolean objects with an initial value of false:
var b1=new Boolean()
var b2=new Boolean(0)
var b3=new Boolean(null)
var b4=new Boolean("")
var b5=new Boolean(false) var b6=new Boolean(NaN) |
All the following lines of code create Boolean objects with an initial value of true:
var b1=new Boolean(true)
var b2=new Boolean("true")
var b3=new Boolean("false")
var b4=new Boolean("Richard") |
The Boolean object's properties and methods are described below: NN: Netscape, IE: Internet Explorer
Properties: Syntax: object.property_name
| Property |
Description |
NN |
IE |
| constructor |
Contains the function that created an object's prototype |
4 |
4 |
| prototype |
Allows addition of properties and methods to the object |
3 |
4 |
Methods: Syntax: object.method_name()
| Method |
Description |
NN |
IE |
| toString() |
Converts a Boolean value to a string. This method is called by JavaScript automatically whenever a Boolean object is used in a situation requiring a string |
4 |
4 |
| valueOf() |
Returns a primitive value ("true" or "false") for the Boolean object |
4 |
4 |
Date Object
The Date object is used to work with dates and times.
Date Object
The Date object is used to work with dates and times. To create an instance of the Date object and assign it to a variable called "d", you do the following:
After creating an instance of the Date object, you can access all the methods of the Date object from the "d" variable. To return the current day in a month (from 1-31) of a Date object, write the following:
The Date object can also have the following parameters:
new Date(milliseconds) new Date(dateString) new Date(yr_num, mo_num, day_num [, hr_num, min_num, sec_num, ms_num]) |
- milliseconds - the number of milliseconds since 01 January, 1970 00:00:00
- dateString - the date in a format that is recognized by the Date.parse method
- yr_num, mo_num, day_num - the year, month or day of the date
- hr_num, min_num, sec_num, ms_num - the hours, minutes, seconds and milliseconds
If you only use Date(), JavaScript creates an object for today's date according to the time on the local machine. Here are some examples on how to create Date objects:
var d=new Date("October 12, 1988 13:14:00")
var d=new Date("October 12, 1988")
var d=new Date(88,09,12,13,14,00)
var d=new Date(88,09,12)
var d=new Date(500) |
The Date object's properties and methods are described below: NN: Netscape, IE: Internet Explorer
Properties:
Syntax: object.property_name
| Property |
Description |
NN |
IE |
| constructor |
Contains the function that created an object's prototype |
4 |
4 |
| prototype |
Allows addition of properties to a date |
3 |
4 |
Methods: Syntax: object.method_name()
| Method |
Description |
NN |
IE |
| Date() |
Returns a Date object |
2 |
3 |
| getDate() |
Returns the date of a Date object (from 1-31) |
2 |
3 |
| getDay() |
Returns the day of a Date object (from 0-6. 0=Sunday, 1=Monday, etc.) |
2 |
3 |
| getMonth() |
Returns the month of a Date object (from 0-11. 0=January, 1=February, etc.) |
2 |
3 |
| getFullYear() |
Returns the year of a Date object (four digits) |
4 |
4 |
| getYear() |
Returns the year of a Date object (from 0-99). Use getFullYear instead !! |
2 |
3 |
| getHours() |
Returns the hour of a Date object (from 0-23) |
2 |
3 |
| getMinutes() |
Returns the minute of a Date object (from 0-59) |
2 |
3 |
| getSeconds() |
Returns the second of a Date object (from 0-59) |
2 |
3 |
| getMilliseconds() |
Returns the millisecond of a Date object (from 0-999) |
4 |
4 |
| getTime() |
Returns the number of milliseconds since midnight 1/1-1970 |
2 |
3 |
| getTimezoneOffset() |
Returns the time difference between the user's computer and GMT |
2 |
3 |
| getUTCDate() |
Returns the date of a Date object in universal (UTC) time |
4 |
4 |
| getUTCDay() |
Returns the day of a Date object in universal time |
4 |
4 |
| getUTCMonth() |
Returns the month of a Date object in universal time |
4 |
4 |
| getUTCFullYear() |
Returns the four-digit year of a Date object in universal time |
4 |
4 |
| getUTCHours() |
Returns the hour of a Date object in universal time |
4 |
4 |
| getUTCMinutes() |
Returns the minutes of a Date object in universal time |
4 |
4 |
| getUTCSeconds() |
Returns the seconds of a Date object in universal time |
4 |
4 |
| getUTCMilliseconds() |
Returns the milliseconds of a Date object in universal time |
4 |
4 |
| parse() |
Returns a string date value that holds the number of milliseconds since January 01 1970 00:00:00 |
2 |
3 |
| setDate() |
Sets the date of the month in the Date object (from 1-31) |
2 |
3 |
| setFullYear() |
Sets the year in the Date object (four digits) |
4 |
4 |
| setHours() |
Sets the hour in the Date object (from 0-23) |
2 |
3 |
| setMilliseconds() |
Sets the millisecond in the Date object (from 0-999) |
4 |
4 |
| setMinutes() |
Set the minute in the Date object (from 0-59) |
2 |
3 |
| setMonth() |
Sets the month in the Date object (from 0-11. 0=January, 1=February) |
2 |
3 |
| setSeconds() |
Sets the second in the Date object (from 0-59) |
2 |
3 |
| setTime() |
Sets the milliseconds after 1/1-1970 |
2 |
3 |
| setYear() |
Sets the year in the Date object (00-99) |
2 |
3 |
| setUTCDate() |
Sets the date in the Date object, in universal time (from 1-31) |
4 |
4 |
| setUTCDay() |
Sets the day in the Date object, in universal time (from 0-6. Sunday=0, Monday=1, etc.) |
4 |
4 |
| setUTCMonth() |
Sets the month in the Date object, in universal time (from 0-11. 0=January, 1=February) |
4 |
4 |
| setUTCFullYear() |
Sets the year in the Date object, in universal time (four digits) |
4 |
4 |
| setUTCHours() |
Sets the hour in the Date object, in universal time (from 0-23) |
4 |
4 |
| setUTCMinutes() |
Sets the minutes in the Date object, in universal time (from 0-59) |
4 |
4 |
| setUTCSeconds() |
Sets the seconds in the Date object, in universal time (from 0-59) |
4 |
4 |
| setUTCMilliseconds() |
Sets the milliseconds in the Date object, in universal time (from 0-999) |
4 |
4 |
| toGMTString() |
Converts the Date object to a string, set to GMT time zone |
2 |
3 |
| toLocaleString() |
Converts the Date object to a string, set to the current time zone |
2 |
3 |
| toString() |
Converts the Date object to a string |
2 |
4 |
Math Object
The built-in Math object includes mathematical constants and functions. Math Object
The built-in Math object includes mathematical constants and functions. You do not need to create the Math object before using it. To store a random number between 0 and 1 in a variable called "r_number":
To store the rounded number of 8.6 in a variable called "r_number":
The Math object's properties and methods are described below: NN: Netscape, IE: Internet Explorer
Properties:
Syntax: object.property_name
| Property |
Description |
NN |
IE |
| E |
Returns the base of a natural logarithm |
2 |
3 |
| LN2 |
Returns the natural logarithm of 2 |
2 |
3 |
| LN10 |
Returns the natural logarithm of 10 |
2 |
3 |
| LOG2E |
Returns the base-2 logarithm of E |
2 |
3 |
| LOG10E |
Returns the base-10 logarithm of E |
2 |
3 |
| PI |
Returns PI |
2 |
3 |
| SQRT1_2 |
Returns 1 divided by the square root of 2 |
2 |
3 |
| SQRT2 |
Returns the square root of 2 |
2 |
3 |
Methods:
Syntax: object.method_name()
| Method |
Description |
NN |
IE |
| abs(x) |
Returns the absolute value of x |
2 |
3 |
| acos(x) |
Returns the arccosine of x |
2 |
3 |
| asin(x) |
Returns the arcsine of x |
2 |
3 |
| atan(x) |
Returns the arctangent of x |
2 |
3 |
| atan2(y,x) |
Returns the angle from the x axis to a point |
2 |
3 |
| ceil(x) |
Returns the nearest integer greater than or equal to x |
2 |
3 |
| cos(x) |
Returns the cosine of x |
2 |
3 |
| exp(x) |
Returns the value of E raised to the power of x |
2 |
3 |
| floor(x) |
Returns the nearest integer less than or equal to x |
2 |
3 |
| log(x) |
Returns the natural log of x |
2 |
3 |
| max(x,y) |
Returns the number with the highest value of x and y |
2 |
3 |
| min(x,y) |
Returns the number with the lowest value of x and y |
2 |
3 |
| pow(x,y) |
Returns the value of the number x raised to the power of y |
2 |
3 |
| random() |
Returns a random number between 0 and 1 |
2 |
3 |
| round(x) |
Rounds x to the nearest integer |
2 |
3 |
| sin(x) |
Returns the sine of x |
2 |
3 |
| sqrt(x) |
Returns the square root of x |
2 |
3 |
| tan(x) |
Returns the tangent of x |
2 |
3 |
String Object
The String object is used to work with text. String object
The String object is used to work with text. The String object's properties and methods are described below:
NN: Netscape, IE: Internet Explorer
Properties:
Syntax: object.property_name
| Property |
Description |
NN |
IE |
| constructor |
|
4 |
4 |
| length |
Returns the number of characters in a string |
2 |
3 |
Methods:
Syntax: object.method_name()
| Method |
Description |
NN |
IE |
| anchor("anchorname") |
Returns a string as an anchor |
2 |
3 |
| big() |
Returns a string in big text |
2 |
3 |
| blink() |
Returns a string blinking |
2 |
|
| bold() |
Returns a string in bold |
2 |
3 |
| charAt(index) |
Returns the character at a specified position |
2 |
3 |
| charCodeAt(i) |
Returns the Unicode of the character at a specified position |
4 |
4 |
| concat() |
Returns two concatenated strings |
4 |
4 |
| fixed() |
Returns a string as teletype |
2 |
3 |
| fontcolor() |
Returns a string in a specified color |
2 |
3 |
| fontsize() |
Returns a string in a specified size |
2 |
3 |
| fromCharCode() |
Returns the character value of a Unicode |
4 |
4 |
| indexOf() |
Returns the position of the first occurrence of a specified string inside another string. Returns -1 if it never occurs |
2 |
3 |
| italics() |
Returns a string in italic |
2 |
3 |
| lastIndexOf() |
Returns the position of the first occurrence of a specified string inside another string. Returns -1 if it never occurs. Note: This method starts from the right and moves left! |
2 |
3 |
| link() |
Returns a string as a hyperlink |
2 |
3 |
| match() |
Similar to indexOf and lastIndexOf, but this method returns the specified string, or "null", instead of a numeric value |
4 |
4 |
| replace() |
Replaces some specified characters with some new specified characters |
4 |
4 |
| search() |
Returns an integer if the string contains some specified characters, if not it returns -1 |
4 |
4 |
| slice() |
Returns a string containing a specified character index |
4 |
4 |
| small() |
Returns a string as small text |
2 |
3 |
| split() |
Splits a string into an array of strings |
4 |
4 |
| strike() |
Returns a string strikethrough |
2 |
3 |
| sub() |
Returns a string as subscript |
2 |
3 |
| substr() |
Returns the specified characters. 14,7 returns 7 characters, from the 14th character (starts at 0) |
4 |
4 |
| substring() |
Returns the specified characters. 7,14 returns all characters from the 7th up to but not including the 14th (starts at 0) |
2 |
3 |
| sup() |
Returns a string as superscript |
2 |
3 |
| toLowerCase() |
Converts a string to lower case |
2 |
3 |
| toUpperCase() |
Converts a string to upper case |
2 |
3 |
|