NewIchapter2CSS
NewIchapter2CSS
11
11
Vidyavardhini’s Bhausaheb .Vartak.Polytechnic developed material on CSS for BVP Students Reference
CHAPTER:2 Prof. Vaghela Parvez:8097538293
• Arrays with named indexes are called associative Example: Prototype Property
arrays (or hashes). • <html>
• JavaScript does not support arrays with named • <head>
indexes. • <title>User-defined objects</title>
• In JavaScript, arrays always use numbered • <script type = "text/javascript">
indexes. • function book(title, author) {
• In JavaScript, arrays use numbered indexes. • this.title = title;
• In JavaScript, objects use named indexes • this.author = author; }
• Objects use names to access its "members". In • </script> </head>
this example, • <body>
• var person = { • <script type = "text/javascript">
• firstName:"Parvez", • var myBook = new
• lastName:"Vaghela", book("Perl","Vaghela");
• age:46}; • book.prototype.price = null;
• person.firstName myBook.price = 100;
12
12
Vidyavardhini’s Bhausaheb .Vartak.Polytechnic developed material on CSS for BVP Students Reference
CHAPTER:2 Prof. Vaghela Parvez:8097538293
Sr.No. Method & Description splice() Adds and/or removes elements from
15
concat() Returns a new array comprised of an array.
1 this array joined with other array(s) and/or toString() Returns a string representing the
16
value(s). array and its elements.
every() Returns true if every element in this unshift() Adds one or more elements to the
2
array satisfies the provided testing function. 17 front of an array and returns the new length
indexOf() Returns the first (least) index of an of the array.
3 element within the array equal to the
specified value, or -1 if none is found. 2.2 Functions:
join() Joins all elements of an array into a Defining a Function:
4 • Functions are the heart of ECMAScript: a
string.
lastIndexOf() Returns the last (greatest) collection of statements that can be run
5 index of an element within the array equal anywhere at anytime.
to the specified value, or -1 if none is found. • Functions are declared with the keyword
function, followed by a set of arguments,
13
13
Vidyavardhini’s Bhausaheb .Vartak.Polytechnic developed material on CSS for BVP Students Reference
CHAPTER:2 Prof. Vaghela Parvez:8097538293
14
14
Vidyavardhini’s Bhausaheb .Vartak.Polytechnic developed material on CSS for BVP Students Reference
CHAPTER:2 Prof. Vaghela Parvez:8097538293
The concat() method, which is used to concatenate var oStringObject= new String(“hello world”);
one or more strings to the primitive value of the alert(oStringObject.slice(-3)); //outputs “rld”
String object. This method actually returns a String alert(oStringObject.substring(-3));
primitive value as a result and leaves the original //outputs“hello world”
String object intact: alert(oStringObject.slice(3, -4));
var oStringObject = new String(“hello “); //outputs “lo w”
var sResult = oStringObject.concat(“world”); alert(oStringObject.substring(3,-4));
alert(sResult); //outputs “hello world” //outputs “hel”
alert(oStringObject); //outputs “hello “
15
15
Vidyavardhini’s Bhausaheb .Vartak.Polytechnic developed material on CSS for BVP Students Reference
CHAPTER:2 Prof. Vaghela Parvez:8097538293
Converting to a number
var iNum1 = parseInt(“1234blue”); // 1234
var iNum2 = parseInt(“0xA”); //returns 10
var iNum3 = parseInt(“22.5”); //returns 22
var iNum4 = parseInt(“blue”); //returns NaN
16
16