









































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










































Lecture 26
During the last lecture we had a discussion on Flow Control & Loops
Compound Statements
for: Example 1
5
‘for’ loops become especially useful when used in conjunction with arrays
We’ll find out about arrays today, and we’ll probe their usefulness as part of ‘for’ loop structures
Today’s Topic: Arrays
Array
An indexed list of elements
We said that a variable is a container that holds a value.
Similarly, an Array can be considered a container as well, but this one can hold multiple values
Array
An indexed list of elements
Example: There are many ways of assigning identifiers to the following fruit
11
strawberry fruit fruit[ 0 ]
orange fruit fruit[ 1 ]
apple fruit fruit[ 2 ]
watermelon fruit fruit[ 3 ]
Array
13
fruit[ 0 ]
Identifier Square bracket
Index
Let’s now take look at one of the advantages of using arrays
16
student = new Array( 4 ) ; //array declaration
student[ 0 ] = “Waseem” ;
student[ 1 ] = “Waqar” ;
student[ 2 ] = “Saqlain” ;
student[ 3 ] = “Daanish” ;
for ( x = 0 ; x < 4 ; x = x + 1 ) {
document.write( student[ x ] ) ;
}
Can you see the advantage of using arrays along with the ‘for’ loop?
Arrays in JavaScript
student = new Array( 4 )
19
This is the identifier of the new instance
The ‘new’ operator creates an instance
This is the parent object (or class) of the new instance
Length of the new instance of ‘Array’
Pair of paren- theses
The ‘assignment’ operator
An Object