JavaScript Lecture 8 - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

JavaScript Lecture 8

Description:

Or var team = new Array('Red Sox', 'Mets', 'Phillies'); (team[0], team[1], ...team[5] ... Red Sox. Pirates. undefined. Numeric and Boolean Arrays ... – PowerPoint PPT presentation

Number of Views:34
Avg rating:3.0/5.0
Slides: 16
Provided by: remusR
Category:
Tags: javascript | lecture | red | sox

less

Transcript and Presenter's Notes

Title: JavaScript Lecture 8


1
JavaScript Lecture 8
  • Assignment (loops)
  • What is an object?
  • Array object
  • Rules (text)
  • Example using arrays

2
  • Book
  • Author
  • Subject
  • Cover color
  • Edition
  • No. of pages
  • In braces are the properties of a general
    category of things called Book. Compare this with
    a class.

3
  • Book Fluency with IT
  • Author Lawrence Snyder
  • Subject IT
  • Cover color Pink
  • Edition 2nd ed.
  • No. of pages 766
  • Now we are talking about a specific book
    Fluency with IT. Values are assigned to
    properties to describe this book.
  • This is comparable with an object.

4
Object
  • User created data-type
  • Objects have properties and methods
  • Methods are used to perform action
  • example studyforquiz() could be a method for
    the object book
  • This method can be called just like any other
    method or function
  • example document.write()

5
  • JavaScript is an Object Oriented Programming
    Language i.e. OOP
  • An OOP language allows object definitions and
    user-created data types
  • Built-in JavaScript objects
  • example document, string, Array

6
Array
  • The Array object is used to store a set of
    values in a single variable name.
  • (www.w3schools.com)
  • Note the A in Array
  • Built-in JavaScript object
  • Has properties and methods associated with it.

7
  • artist_1, artist_2,.artist_5.
  • Could you somehow store all these values in a
    single variable name artist?
  • Yes!!
  • artist5

8
  • team10
  • This array describes a team of 10 players.
  • The players can be referenced as team0,
    team1, ..team9
  • An Array is thus a collection of variables of the
    same data type and (usually) the same size.

9
Defining Arrays
  • var team new Array()
  • team0 Red Sox
  • team1 Mets
  • team2 Phillies
  • Or var team new Array(3)
  • team0 Red Sox
  • team1 Mets
  • team2 Phillies
  • Or var team new Array(Red Sox, Mets,
    Phillies)

10
  • (team0, team1, team5)
  • i5
  • Document.write(teami)

11
Accessing Arrays using the index
  • var team new Array()
  • team0 Red Sox
  • document.write(team0)
  • team0 Pirates
  • document.write(team0)
  • document.write(team10)
  • Var a
  • document.write(a)

12
  • Output
  • Red Sox
  • Pirates
  • undefined

13
Numeric and Boolean Arrays
  • Similarly numbers or boolean values could be used
    inside arrays
  • var submarks new Array(90, 70, 120)
  • var boolarray new Array(true, true, false
  • Csubmarks1 submarks2

14
Using for loops to access arrays
  • lthtmlgt
  • ltheadgtlttitlegt"Array1"lt/titlegtlt/headgt
  • ltbodygt
  • ltscript type"text/javascript"gt
  • var team new Array()
  • team0 "Red Sox"
  • team1 "Mets"
  • team2 "Phillies"
  • for (i0ilt3i)
  • document.write(teami)
  • document.write("ltbrgt")

15
  • var marks new Array(250)
  • marks0 100
  • Marks1120
  • C marks0 marks1
Write a Comment
User Comments (0)
About PowerShow.com