Republic of Iraq
Ministry of Higher Education and
Scientific Research
University of Babylon
College of Information Technology
Department of network
التقرير النهائي
) الثاني/ الفصل الدراسي (األول2019-2020 للعام الدراسي
jQuery
أعداد الطالب
أحمد صالح سالم المسلماوي
بأشراف األستاذ
حيدر محمد حبيب.د
Table Of Content
JavaScript Objects Introduction ................................................................................................................. 3
Object Oriented Programming ....................................................................................................... 3
Properties ........................................................................................................................................... 3
Methods .............................................................................................................................................. 3
JavaScript String Object ......................................................................................................................... 4
Examples ............................................................................................................................................ 4
Complete String Object Reference ............................................................................................... 4
String object....................................................................................................................................... 4
JavaScript Date Object ........................................................................................................................... 5
Examples ............................................................................................................................................ 5
Complete Date Object Reference .................................................................................................. 5
Create a Date Object ........................................................................................................................ 5
Set Dates ............................................................................................................................................. 6
Compare Two Dates ......................................................................................................................... 6
JavaScript Array Object .......................................................................................................................... 6
Examples ............................................................................................................................................ 6
Complete Array Object Reference ................................................................................................ 7
Create an Array ................................................................................................................................. 7
Access an Array ................................................................................................................................ 8
Modify Values in an Array ............................................................................................................... 8
JavaScript Boolean Object...................................................................................................................... 8
Examples ............................................................................................................................................ 8
Complete Boolean Object Reference ........................................................................................... 8
Create a Boolean Object ................................................................................................................. 8
JavaScript Objects Introduction
JavaScript is an Object Oriented Programming (OOP) language.
An OOP language allows you to define your own objects and make your own variable types.
Object Oriented Programming
JavaScript is an Object Oriented Programming (OOP) language. An OOP language allows you to define your
own objects and make your own variable types.
However, creating your own objects will be explained later, in the Advanced JavaScript section. We will start
by looking at the built-in JavaScript objects, and how they are used. The next pages will explain each built-
in JavaScript object in detail.
Note that an object is just a special kind of data. An object has properties and methods.
Properties
Properties are the values associated with an object.
In the following example we are using the length property of the String object to return the number of
characters in a string:
<script type="text/javascript">
var txt="Hello World!";
document.write(txt.length);
</script>
The output of the code above will be:
12
Methods
Methods are the actions that can be performed on objects.
In the following example we are using the toUpperCase() method of the String object to display a text in
uppercase letters:
<script type="text/javascript">
var str="Hello world!";
document.write(str.toUpperCase());
</script>
The output of the code above will be:
HELLO WORLD!
JavaScript String Object
The String object is used to manipulate a stored piece of text.
Examples
Return the length of a string
How to use the length property to find the length of a string.
Style strings
How to style strings.
The indexOf() method
How to use the indexOf() method to return the position of the first occurrence of a specified string value in a
string.
The match() method
How to use the match() method to search for a specified string value within a string and return the string
value if found
Replace characters in a string - replace()
How to use the replace() method to replace some characters with some other characters in a string.
Complete String Object Reference
For a complete reference of all the properties and methods that can be used with the String object, go to
our complete String object reference.
The reference contains a brief description and examples of use for each property and method!
String object
The String object is used to manipulate a stored piece of text.
Examples of use:
The following example uses the length property of the String object to find the length of a string:
var txt="Hello world!";
document.write(txt.length);
The code above will result in the following output:
12
The following example uses the toUpperCase() method of the String object to convert a string to uppercase
letters:
var txt="Hello world!";
document.write(txt.toUpperCase());
The code above will result in the following output:
HELLO WORLD!
JavaScript Date Object
The Date object is used to work with dates and times.
Examples
Return today's date and time
How to use the Date() method to get today's date.
getTime()
Use getTime() to calculate the years since 1970.
setFullYear()
How to use setFullYear() to set a specific date.
toUTCString()
How to use toUTCString() to convert today's date (according to UTC) to a string.
getDay()
Use getDay() and an array to write a weekday, and not just a number.
Display a clock
How to display a clock on your web page.
Complete Date Object Reference
For a complete reference of all the properties and methods that can be used with the Date object, go to our
complete Date object reference.
The reference contains a brief description and examples of use for each property and method!
Create a Date Object
The Date object is used to work with dates and times.
The following code create a Date object called myDate:
var myDate=new Date()
Note: The Date object will automatically hold the current date and time as its initial value!
Set Dates
We can easily manipulate the date by using the methods available for the Date object.
In the example below we set a Date object to a specific date (14th January 2010):
var myDate=new Date();
myDate.setFullYear(2010,0,14);
And in the following example we set a Date object to be 5 days into the future:
var myDate=new Date();
myDate.setDate(myDate.getDate()+5);
Note: If adding five days to a date shifts the month or year, the changes are handled automatically by the
Date object itself!
Compare Two Dates
The Date object is also used to compare two dates.
The following example compares today's date with the 14th January 2010:
var myDate=new Date();
myDate.setFullYear(2010,0,14);
var today = new Date();
if (myDate>today)
{
alert("Today is before 14th January 2010");
}
else
{
alert("Today is after 14th January 2010");
}
JavaScript Array Object
The Array object is used to store multiple values in a single variable.
Examples
Create an array
Create an array, assign values to it, and write the values to the output.
For...In Statement
How to use a for...in statement to loop through the elements of an array.
Join two arrays - concat()
How to use the concat() method to join two arrays.
Put array elements into a string - join()
How to use the join() method to put all the elements of an array into a string.
Literal array - sort()
How to use the sort() method to sort a literal array.
Numeric array - sort()
How to use the sort() method to sort a numeric array.
Complete Array Object Reference
For a complete reference of all the properties and methods that can be used with the Array object, go to our
complete Array object reference.
The reference contains a brief description and examples of use for each property and method!
Create an Array
The following code creates an Array object called myCars:
var myCars=new Array();
There are two ways of adding values to an array (you can add as many values as you need to define as
many variables you require).
1:
var myCars=new Array();
myCars[0]="Saab";
myCars[1]="Volvo";
myCars[2]="BMW";
You could also pass an integer argument to control the array's size:
var myCars=new Array(3);
myCars[0]="Saab";
myCars[1]="Volvo";
myCars[2]="BMW";
2:
var myCars=new Array("Saab","Volvo","BMW");
Note: If you specify numbers or true/false values inside the array then the type of variables will be numeric
or Boolean instead of string.
Access an Array
You can refer to a particular element in an array by referring to the name of the array and the index
number. The index number starts at 0.
The following code line:
document.write(myCars[0]);
will result in the following output:
Saab
Modify Values in an Array
To modify a value in an existing array, just add a new value to the array with a specified index number:
myCars[0]="Opel";
Now, the following code line:
document.write(myCars[0]);
will result in the following output:
Opel
JavaScript Boolean Object
The Boolean object is used to convert a non-Boolean value to a Boolean value (true or false).
Examples
Check Boolean value
Check if a Boolean object is true or false.
Complete Boolean Object Reference
For a complete reference of all the properties and methods that can be used with the Boolean object, go to
our complete Boolean object reference.
The reference contains a brief description and examples of use for each property and method!
Create a Boolean Object
The Boolean object represents two values: "true" or "false".
The following code creates a Boolean object called myBoolean:
var myBoolean=new Boolean();
Note: If the Boolean object has no initial value or if it is 0, -0, null, "", false, undefined, or NaN, the object
is set to 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 myBoolean=new Boolean();
var myBoolean=new Boolean(0);
var myBoolean=new Boolean(null);
var myBoolean=new Boolean("");
var myBoolean=new Boolean(false);
var myBoolean=new Boolean(NaN);
And all the following lines of code create Boolean objects with an initial value of true:
var myBoolean=new Boolean(true);
var myBoolean=new Boolean("true");
var myBoolean=new Boolean("false");
var myBoolean=new Boolean("Richard");