Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

JavaScript: Arrays and Objects, Study notes of Computer Science

An introduction to javascript arrays and objects. It explains how to declare and handle arrays, access array elements, and use array functions such as sort(), reverse(), and join(). Additionally, it covers the basics of javascript objects, including properties and frequently used objects like navigator, window, and document.

Typology: Study notes

Pre 2010

Uploaded on 07/30/2009

koofers-user-vq8
koofers-user-vq8 🇺🇸

10 documents

1 / 10

Toggle sidebar

Related documents


Partial preview of the text

Download JavaScript: Arrays and Objects and more Study notes Computer Science in PDF only on Docsity! 1 JavaScript (Arrays)  Image you need to keep track of the scores of students in a class and you have 50 students  Declaring and handling 50 variables is not an easy task  Arrays come to the rescue  Array – Collection of values that can be treated as a unit and where you can handle each individual entry (similar to an egg carton)  You can visualize an array as a set of variables one after another  There are several ways to define arrays. var scienceScores = new Array(); // Creates an empty array var mathScores = new Array(3); // Creates an array with 3 entries var englishScores = [77, 88, 65]; // Creates an array with 3 entries // having the specified values 2 JavaScript (Arrays)  To access elements of an array  Use the [ ] operator  Integer Index values starting at zero will represent each element  Accessing array elements mathScores[0] = 70; // Assigning 70 to the first array element mathScores[1] = 80; // Assigning 80 to the second array element var total = mathScores[0] + mathScores[1]; // reading the first // and second elements 5 JavaScript (Objects)  An example of an object is the navigator object which provides information about the web browser  Among the navigator object properties you can find  appName – web browser name  appCodeName code name for the browser  You can access properties by specifying the object name, a period, and the property name or by specifying the property name using array-like syntax navigator.appName navigator[“appName”]  Notice that you can read of modify properties using the above notation  Example 3 (See Example3.html) 6 JavaScript (Frequently Used Objects)  window – Represents the window displaying the document (either the web browser window or a frame within a window). Some attributes of this object are:  closed – boolean value set to true if the window has been closed  status – text that appears in the browser’s status line  navigator – Object we described earlier  document – Refers to the document object associated with the window. This object represents the HTML document displayed in the window  location - Refers to the location object associated with the window. This object represents the URL of the document being displayed  Example 4 (See Example4.html)  This example relies on the for in construct that allow us to go through the properties for an object 7 JavaScript (Example)  By making use of functions, object properties and forms we can now define an html document with JavaScript that generates customized multiplication tables  Example 5 (See Example5.html)  Notice how we can pass properties of elements of the form to the multiplicationTable function
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved