HTML and CSS Reference
In-Depth Information
Figure 8.11 The adultbook object and its properties.
8.4.2 The for/in Loop
JavaScript provides the for/in loop, which can be used to iterate through a list of object
properties or array elements. The for/in loop reads: for each property in an object (or for
each element in an array) get the name of each property (element), in turn, and for each
of the properties (elements), execute the statements in the block that follows.
The for/in loop is a convenient mechanism for looping through the properties of an
object.
FORMAT
for(var property_name in object){
statements;
}
EXAMPLE 8.10
<html>
<head><title>User-defined objects</title>
<script type = "text/javascript">
1
function book(title, author, publisher) {
2
this.title = title;
this.author = author;
this.publisher = publisher;
3
this.show=show;
// Define a method for the object
}
 
 
Search WWH ::




Custom Search