12- Javascript(lect 3) php
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
154
On Slideshare
154
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
0
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Hidaya Institute of Science & Technology www.histpk.org A Division of Hidaya Trust, Pakistan
  • 2. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org JAVASCRIPT BY: MUHAMMAD BAQAR QAZI
  • 3. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org ARRAYS •An array is an ordered collection of values. •Each value is called an element, and each element has a numeric position in the array, known as its index. •To create a new array object, use the static Arrayobject’s constructor method. For example: •var myArray = new Array(); •An array object automatically has a length property (0 for an empty array). •Should you want to pre-size the array (for example, preload entries with null values), you can specify an initial size as a parameter to the constructor. •For example, here is how to create a new array to hold information about a 500-item collection: •var myCDCollection = new Array(500);
  • 4. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org ARRAYS •Entering data into an array is as simple as creating a series of assignment statements, one for each element of the array. • Listing generates an array containing a list of the eight planets of the solar system. •solarSys = new Array(); •solarSys[0] = "Mercury"; •solarSys[1] = "Venus"; •solarSys[2] = "Earth"; •solarSys[3] = "Mars"; •solarSys[4] = "Jupiter"; •solarSys[5] = "Saturn"; •solarSys[6] = "Uranus"; •solarSys[7] = "Neptune";
  • 5. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org ARRAYS •A more compact way to create an array is available called a dense array by supplying the data as comma-delimited parameters to the Array()constructor: solarSys = new Array("Mercury","Venus","Earth","Mars"); •JavaScript provides one more way to create a dense array. • This improved approach does not require the Arrayobject constructor. •Instead, JavaScript (as of version 1.2) accepts what is called literal notation to generate an array. •var regionalOffices = ["New York", "Chicago", "Houston", "Portland"]; •Below Is syntax For Multidimensional arrays. •var regionalOffices = [ •["New York", "Shirley Smith", 300000], •["Chicago", "Todd Gaston", 250000],["Houston", "Leslie Jones", 350000], ["Portland", "Harold Zoot", 225000] •];
  • 6. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Property Description length Reflects the number of elements in an array. Method Description concat() Returns a new array comprised of this array joined with other array(s) and/or value(s). indexOf() Returns the first (least) index of an element within the array equal to the specified value, or -1 if none is found. join() Joins all elements of an array into a string. lastIndexOf() Returns the last (greatest) index of an element within the array equal to the specified value, or -1 if none is found. pop() Removes the last element from an array and returns that element. push() Adds one or more elements to the end of an array and returns the new length of the array. reverse() Reverses the order of the elements of an array -- the first becomes the last, and the last becomes the first. slice() Extracts a section of an array and returns a new array.
  • 7. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org STRING The String object let's you work with a series of characters and  wraps Javascript's string primitive data type with a number of  helper methods. Properties: string.length; Methods: •charCodeAt(): •The charCodeAt() method returns the Unicode of the character  at the specified index in a string. •The index of the first character is 0, and the index of the last  character in a string called "txt", is txt.length-1. string.charCodeAt(index); Here is a list of each method and its descrip
  • 8. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org STRING •The fromCharCode() method converts Unicode values to  characters. •This method is a static method of the String object. The syntax  is always String.fromCharCode() and not string.fromCharCode(). •String.fromCharCode(n1, n2, ..., nX)
  • 9. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org STRINGMethod Description charAt() Returns the character at the specified index. charCodeAt() Returns a number indicating the Unicode value of the character at the given  index. concat() Combines the text of two strings and returns a new string. indexOf() Returns the index within the calling String object of the first occurrence of the  specified value, or -1 if not found. lastIndexOf() Returns the index within the calling String object of the last occurrence of the  specified value, or -1 if not found. localeCompare() Returns a number indicating whether a reference string comes before or after or  is the same as the given string in sort order. match() Used to match a regular expression against a string. replace() Used to find a match between a regular expression and a string, and to replace  the matched substring with a new substring. search() Executes the search for a match between a regular expression and a specified  string. slice() Extracts a section of a string and returns a new string. split() Splits a String object into an array of strings by separating the string into  substrings. substr() Returns the characters in a string beginning at the specified location through  the specified number of characters. substring() Returns the characters in a string between two indexes into the string. toLocaleLowerCase() The characters within a string are converted to lower case while respecting the  current locale. toLocaleUpperCase() The characters within a string are converted to upper case while respecting the  current locale. toLowerCase() Returns the calling string value converted to lower case. toString() Returns a string representing the specified object. toUpperCase() Returns the calling string value converted to uppercase. valueOf() Returns the primitive value of the specified object.
  • 10. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org SETINTERVAL AND CLEAR INTERVAL setInterval(): •The setInterval() method calls a function or evaluates an expression at specified intervals (in milliseconds). •The setInterval() method will continue calling the function until clearInterval() is called, or the window is closed. •The ID value returned by setInterval() is used as the parameter for the clearInterval() method. setInterval(code,millisec) clearInterval(): •The clearInterval() method clears a timer set with he setInterval() method. •The ID value returned by setInterval() is used as the parameter for the clearInterval() method. •clearInterval(id_of_setinterval)