JavaScript – Objects
1
Object - Definition
2
Object
Methods
3
Object - Example
person
4
Object - Properties�
5
Object - Method
6
Object Creation
7
Direct Instance of an Object
8
Create an object from a template
9
JavaScript – Built-in Objects
10
String Object
11
String - Methods
12
Method Name | Description |
big() | Displays a string in a big font |
charAt() | Returns the character at a specified position |
concat() | Joins two or more strings. |
indexOf() | Returns the position of the first occurrence of a specified string value in a string. |
String - Methods
13
Method Name | Description |
match() | Searches for a specified value in a string |
replace() | Replaces some characters with some other characters in a string |
search() | Searches a string for a specified value |
substring() | Extracts the characters in a string between two specified indices |
String - Methods
14
Method | Description |
toLowerCase() | Displays a string in lowercase letters |
toUpperCase() | Displays a string in uppercase letters |
valueOf() | Returns the primitive value of a String object |
split() | Splits a string into an array of strings. |
String - Methods
15
Method | Description |
Displays a blinking string | |
Displays a string in bold | |
Displays a string in a specified color | |
Displays a string in a specified size. | |
Displays a string in italic. |
String - Properties
16
Method | Description |
constructor | A reference to the function that created the object. |
length | Returns the number of characters in a string. |
Example - String Object
17
Date Object
var myDate=new Date()
18
Date Object - Methods
19
Method | Description |
Date() | Returns today's date and time |
getDate() | Returns the day of the month from a Date object |
getDay() | Returns the day of the week from a Date object (from 0-6) |
getMonth() | Returns the month from a Date object (from 0-11) |
getFullYear() | Returns the year, as a four-digit number, from a Date object |
Date Object - Methods
20
Method | Description |
getYear() | Returns the year in two-digit format. |
getHours() | Returns the hour of a Date object (from 0-23) |
getMinutes() | Returns the minutes of a Date object (from 0-59) |
getSeconds() | Returns the seconds of a Date object (from 0-59) |
getTime() | Returns the number of milliseconds since midnight Jan 1, 1970 |
Date Object - Methods
21
Method | Description |
setDate() | Sets the day of the month in a Date object (from 1-31) |
setMonth() | Sets the month in a Date object (from 0-11) |
setFullYear() | Sets the year in a Date object (four digits) |
setYear() | Sets the year in the Date object (two) |
setHours() | Sets the hour in a Date object (from 0-23) |
Date Object - Methods
22
Method | Description |
setMinutes() | Set the minutes in a Date object (from 0-59). |
setSeconds() | Sets the seconds in a Date object (from 0-59) |
setTime() | Calculates a date and time by adding or subtracting a specified number of milliseconds to/from midnight January 1, 1970 |
toString() | Converts a Date object to a string |
Example - Date Object
23
Array Object
var myArray=new Array()
24
Array
var mycars=new Array() mycars[0]="Saab"
mycars[1]="Volvo“
var mycars=new Array("Saab","Volvo")
25
Array
document.write(mycars[0])
26
Array Object - Methods
27
Method | Description |
concat() | Joins two or more arrays and returns the result. |
join() | Puts all the elements of an array into a string. The elements are separated by a specified delimiter |
pop() | Removes and returns the last element of an array. |
push() | Adds one or more elements to the end of an array. |
reverse() | Reverses the order of the elements in an array |
Array Object - Methods
28
Method | Description |
sort() | Sorts the elements of an array |
toString() | Converts an array to a string and returns the result |
Array Object - Properties
29
Property Name | Description |
length | Sets or returns the number of elements in an array. |
Example - Array Object
30
Boolean Object
31
Boolean Object
var myBoolean=new Boolean()
32
JavaScript - Math Object
33
Math Object - Methods
34
Method Name | Description |
abs(x) | Returns the absolute value of a number. |
ceil(x) | Returns the value of a number rounded upwards to the nearest integer |
floor(x) | Returns the value of a number rounded downwards to the nearest integer |
max(x,y) | Returns the number with the highest value of x and y |
Math Object - Methods
35
Method Name | Description |
min(x,y) | Returns the number with the lowest value of x and y |
pow(x,y) | Returns the value of x to the power of y |
random() | Returns a random number between 0 and 1 |
round(x) | Rounds a number to the nearest integer. |
Math Object - Methods
36
Method Name | Description |
sqrt(x) | Returns the square root of a number. |
sin(x) | Returns the sine of a number. |
cos(x) | Returns the cosine of a number. |
tan(x) | Returns the tangent of an angle. |
Math Object - Properties
37
Property Name | Description |
PI | Returns PI (approx. 3.14159) |
Example - Math Object
38