Javascript Objects
Javascript Objects
The Array object is used to store multiple values in a single variable. For a tutorial about Arrays, read our JavaScript Array Object tutorial.
Boolean Object
The Boolean object is used to convert a non-Boolean value to a Boolean value (true or false). For a tutorial about the Boolean object, read our JavaScript Boolean Object tutorial.
Date Object
The Date object is used to work with dates and times. Date objects are created with new Date(). There are four ways of instantiating a date: var d = new Date(); var d = new Date(milliseconds); var d = new Date(dateString); var d = new Date(year, month, day, hours, minutes, seconds, milliseconds); For a tutorial about date and times, read our JavaScript Date Object tutorial.
Returns the day of the week (from 0-6) Returns the year (four digits) Returns the hour (from 0-23) Returns the milliseconds (from 0-999) Returns the minutes (from 0-59) Returns the month (from 0-11) Returns the seconds (from 0-59) Returns the number of milliseconds since midnight Jan 1, 1970 Returns the time difference between UTC time and local time, in getTimezoneOffset() minutes getUTCDate() Returns the day of the month, according to universal time (from 1-31) getUTCDay() Returns the day of the week, according to universal time (from 0-6) getUTCFullYear() Returns the year, according to universal time (four digits) getUTCHours() Returns the hour, according to universal time (from 0-23) getUTCMilliseconds() Returns the milliseconds, according to universal time (from 0-999) getUTCMinutes() Returns the minutes, according to universal time (from 0-59) getUTCMonth() Returns the month, according to universal time (from 0-11) getUTCSeconds() Returns the seconds, according to universal time (from 0-59) getYear() Deprecated. Use the getFullYear() method instead Parses a date string and returns the number of milliseconds since parse() midnight of January 1, 1970 setDate() Sets the day of the month of a date object setFullYear() Sets the year (four digits) of a date object setHours() Sets the hour of a date object setMilliseconds() Sets the milliseconds of a date object setMinutes() Set the minutes of a date object setMonth() Sets the month of a date object setSeconds() Sets the seconds of a date object Sets a date and time by adding or subtracting a specified number of setTime() milliseconds to/from midnight January 1, 1970 setUTCDate() Sets the day of the month of a date object, according to universal time setUTCFullYear() Sets the year of a date object, according to universal time (four digits) setUTCHours() Sets the hour of a date object, according to universal time setUTCMilliseconds() Sets the milliseconds of a date object, according to universal time setUTCMinutes() Set the minutes of a date object, according to universal time setUTCMonth() Sets the month of a date object, according to universal time setUTCSeconds() Set the seconds of a date object, according to universal time setYear() Deprecated. Use the setFullYear() method instead toDateString() Converts the date portion of a Date object into a readable string
toGMTString() toISOString() toJSON() toLocaleDateString() toLocaleTimeString() toLocaleString() toString() toTimeString() toUTCString() UTC() valueOf()
Deprecated. Use the toUTCString() method instead Returns the date as a string, using the ISO standard Returns the date as a string, formated as a JSON date Returns the date portion of a Date object as a string, using locale conventions Returns the time portion of a Date object as a string, using locale conventions Converts a Date object to a string, using locale conventions Converts a Date object to a string Converts the time portion of a Date object to a string Converts a Date object to a string, according to universal time Returns the number of milliseconds in a date string since midnight of January 1, 1970, according to universal time Returns the primitive value of a Date object
Math Object
The Math object allows you to perform mathematical tasks. Math is not a constructor. All properties/methods of Math can be called by using Math as an object, without creating it.
Syntax
var x = Math.PI; // Returns PI var y = Math.sqrt(16); // Returns the square root of 16 For a tutorial about the Math object, read our JavaScript Math Object tutorial.
SQRT2
Number Object
The Number object is an object wrapper for primitive numeric values. Number objects are created with new Number().
Syntax
var num = new Number(value); Note: If the value parameter cannot be converted into a number, it returns NaN (Not-a-Number).
String Object
The String object is used to manipulate a stored piece of text. String objects are created with new String().
Syntax
var txt = new String("string"); or more simply: var txt = "string"; For a tutorial about the String object, read our JavaScript String Object tutorial.
Description Returns the function that created the String object's prototype Returns the length of a string Allows you to add properties and methods to an object
bold() Displays a string in bold fixed() Displays a string using a fixed-pitch font fontcolor() Displays a string using a specified color fontsize() Displays a string using a specified size italics() Displays a string in italic link() Displays a string as a hyperlink small() Displays a string using a small font strike() Displays a string with a strikethrough sub() Displays a string as subscript text sup() Displays a string as superscript text
RegExp Object
A regular expression is an object that describes a pattern of characters. Regular expressions are used to perform pattern-matching and "search-and-replace" functions on text.
Syntax
var patt=new RegExp(pattern,modifiers); or more simply: var patt=/pattern/modifiers;
pattern specifies the pattern of an expression modifiers specify if a search should be global, case-sensitive, etc.
For a tutorial about the RegExp object, read our JavaScript RegExp Object tutorial.
Modifiers
Modifiers are used to perform case-insensitive and global searches: Modifier i g m Description Perform case-insensitive matching Perform a global match (find all matches rather than stopping after the first match) Perform multiline matching
Brackets
Brackets are used to find a range of characters: Expression Description [abc] Find any character between the brackets [^abc] Find any character not between the brackets [0-9] Find any digit from 0 to 9 [A-Z] Find any character from uppercase A to uppercase Z [a-z] Find any character from lowercase a to lowercase z [A-z] Find any character from uppercase A to lowercase z [adgk] Find any character in the given set [^adgk] Find any character outside the given set (red|blue|green) Find any of the alternatives specified
Metacharacters
Metacharacters are characters with a special meaning: Metacharacter . \w \W \d \D \s \S \b \B \0 \n \f \r \t \v \xxx \xdd \uxxxx Description Find a single character, except newline or line terminator Find a word character Find a non-word character Find a digit Find a non-digit character Find a whitespace character Find a non-whitespace character Find a match at the beginning/end of a word Find a match not at the beginning/end of a word Find a NUL character Find a new line character Find a form feed character Find a carriage return character Find a tab character Find a vertical tab character Find the character specified by an octal number xxx Find the character specified by a hexadecimal number dd Find the Unicode character specified by a hexadecimal number xxxx
Quantifiers
Quantifier n+ n* n? n{X} n{X,Y} n{X,} n$ ^n ?=n ?!n Description Matches any string that contains at least one n Matches any string that contains zero or more occurrences of n Matches any string that contains zero or one occurrences of n Matches any string that contains a sequence of X n's Matches any string that contains a sequence of X to Y n's Matches any string that contains a sequence of at least X n's Matches any string with n at the end of it Matches any string with n at the beginning of it Matches any string that is followed by a specific string n Matches any string that is not followed by a specific string n
Window Object
The window object represents an open window in a browser. If a document contain frames (<frame> or <iframe> tags), the browser creates one window object for the HTML document, and one additional window object for each frame. Note: There is no public standard that applies to the Window object, but all major browsers support it.
innerHeight innerWidth length location name navigator opener outerHeight outerWidth pageXOffset pageYOffset parent screen screenLeft screenTop screenX screenY self status top
Sets or returns the inner height of a window's content area Sets or returns the inner width of a window's content area Returns the number of frames (including iframes) in a window Returns the Location object for the window (See Location object) Sets or returns the name of a window Returns the Navigator object for the window (See Navigator object) Returns a reference to the window that created the window Sets or returns the outer height of a window, including toolbars/scrollbars Sets or returns the outer width of a window, including toolbars/scrollbars Returns the pixels the current document has been scrolled (horizontally) from the upper left corner of the window Returns the pixels the current document has been scrolled (vertically) from the upper left corner of the window Returns the parent window of the current window Returns the Screen object for the window (See Screen object) Returns the x coordinate of the window relative to the screen Returns the y coordinate of the window relative to the screen Returns the x coordinate of the window relative to the screen Returns the y coordinate of the window relative to the screen Returns the current window Sets the text in the statusbar of a window Returns the topmost browser window
Displays a dialog box that prompts the visitor for input Resizes the window by the specified pixels Resizes the window to the specified width and height Scrolls the content by the specified number of pixels Scrolls the content to the specified coordinates Calls a function or evaluates an expression at specified intervals (in milliseconds) Calls a function or evaluates an expression after a specified number of milliseconds
Navigator Object
The navigator object contains information about the browser. Note: There is no public standard that applies to the navigator object, but all major browsers support it.
History Object
The history object contains the URLs visited by the user (within a browser window).
The history object is part of the window object and is accessed through the window.history property. Note: There is no public standard that applies to the history object, but all major browsers support it.
Location Object
The location object contains information about the current URL. The location object is part of the window object and is accessed through the window.location property. Note: There is no public standard that applies to the location object, but all major browsers support it.
protocol search