>> JavaScript: Arrays

Slides:



Advertisements
Similar presentations
CATHERINE AND ANNIE Python: Part 3. Intro to Loops Do you remember in Alice when you could use a loop to make a character perform an action multiple times?
Advertisements

Chapter 6 Lists and Dictionaries CSC1310 Fall 2009.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Arrays.
JavaScript Part 6. Calling JavaScript functions on an event JavaScript doesn’t have a main function like other programming languages but we can imitate.
String and Lists Dr. Benito Mendoza. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list List.
EIW: Javascript the Language1 The JavaScript Language.
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
CSE 341 Lecture 24 JavaScript arrays and objects slides created by Marty Stepp
 2004 Prentice Hall, Inc. All rights reserved. 1 Chapter 11 - JavaScript: Arrays Outline 11.1 Introduction 11.2 Arrays 11.3 Declaring and Allocating Arrays.
Lists in Python.
Using Client-Side Scripts to Enhance Web Applications 1.
Java Script: Arrays (Chapter 11 in [2]). 2 Outline Introduction Introduction Arrays Arrays Declaring and Allocating Arrays Declaring and Allocating Arrays.
Perl Variables: Array Web Programming1. Review: Perl Variables Scalar ► e.g. $var1 = “Mary”; $var2= 1; ► holds number, character, string Array ► e.g.
ECA 225 Applied Interactive Programming ECA 225 Applied Online Programming javascript arrays.
Class02 More Arrays MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 1/14/2016.
JavaScript and Ajax (JavaScript Arrays) Week 5 Web site:
Chapter 5 Murach's JavaScript and jQuery, C1© 2012, Mike Murach & Associates, Inc.Slide 1.
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
Arrays and Collections
String and Lists Dr. José M. Reyes Álamo.
Chapter 11 - JavaScript: Arrays
>> Fundamental Concepts in PHP
CGS 3066: Web Programming and Design Spring 2017
Chapter 6: Using Arrays.
>> JavaScript: Document Object Model
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
Computer Programming BCT 1113
Microsoft Visual Basic 2005: Reloaded Second Edition
Two Dimensional Arrays
Eric Roberts and Jerry Cain
Chapter 6 Arrays Lecturer: Mrs Rohani Hassan
>> PHP: Arrays.
Class06 Arrays MIS 3502 Jeremy Shafer Department of MIS
Foundations of Programming: Arrays
Chapter 7: Array.
Basics of JavaScript Programming Language
SEEM4570 Tutorial 05: JavaScript as OOP
JavaScript Syntax and Semantics
Array Array is a variable which holds multiple values (elements) of similar data types. All the values are having their own index with an array. Index.
JavaScript Create Array object
Loops and Arrays.
Week#2 Day#1 Java Script Course
JavaScript Functions and Arrays
Web Systems Development (CSC-215)
Arrays MIS 3502 Jeremy Shafer Department of MIS Fox School of Business
Objectives Create an array Work with array properties and methods
Web Systems Development (CSC-215)
ARRAYS MIT-AITI Copyright 2001.
Perl Variables: Array Web Programming.
Lists in Python.
Web Systems Development (CSC-215)
PHP.
JavaScript Arrays.
String and Lists Dr. José M. Reyes Álamo.
MSIS 655 Advanced Business Applications Programming
Topics Sequences Introduction to Lists List Slicing
Array?.
Arrays.
Programming Control Structures with JavaScript Part 2
CIS16 Application Development and Programming using Visual Basic.net
Arrays Part 2.
Loops and Arrays in JavaScript
Topics Sequences Introduction to Lists List Slicing
And now for something completely different . . .
EET 2259 Unit 9 Arrays Read Bishop, Sections 6.1 to 6.3.
INFO/CSE 100, Spring 2006 Fluency in Information Technology
CGS 3066: Web Programming and Design Spring 2016
Lecture 9: JavaScript Syntax
Python List.
Introduction to Computer Science
Presentation transcript:

>> JavaScript: Arrays

Web-Based Systems - Misbhauddin Arrays Store multiple values in a Single Object/Variable SYNTAX SYNTAX for Initializers var array-name = new Array(); Elements keyword Built-in var array-name = new Array(value1, value2,………..); [0] [1] Index [0]…….[size-1] Other Initialization Method var array-name = new Array(size); array-name[index] = “value”; Web-Based Systems - Misbhauddin

Web-based Systems | Misbhauddin Values in Arrays Accessed as if they are in a numbered list. Important: Numbering of this list starts from zero (not one) NUMBERING ITEMS IN AN ARRAY Each item is given a number automatically called as index INDEX VALUE white 1 black 2 custom var colors; colors = [‘white’, ‘black’, ‘custom’]; Web-based Systems | Misbhauddin

Web-based Systems | Misbhauddin Values in Arrays ACCESSING ITEMS IN AN ARRAY Accessing requires specification of array name along with index number USAGE: array-name[index-value] Note: Index value should be in-bounds otherwise “undefined” error Accesses the third element in the array colors itemThree = colors[2]; Web-based Systems | Misbhauddin

Arrays – Literal Method Another way of creating Arrays SYNTAX var array-name = [element-1, element-2, ………] keyword Web-Based Systems - Misbhauddin

Web-Based Systems - Misbhauddin Types of Arrays Types of Arrays 1. Heterogeneous Arrays: Arrays with elements of different data types var lists = [1, “name”, true]; 2. Multi-dimensional Arrays: Arrays with multiple rows var lists = [[1, 2], [3, 4], [5, 6]; 3. Jagged Arrays: Arrays with multiple rows, each row with different no. elements var lists = [[1, 2], [3, 4, 5], [5, 6, 7, 8]; Web-Based Systems - Misbhauddin

Web-Based Systems - Misbhauddin Arrays - Functions Arrays are Objects. Hence, they have properties & methods (just like strings) Properties .length – returns the length of the array Methods array1.concat(array2) – joins two arrays .join() – turn an array into a string .pop() – Returns the last element & deletes it .push(element) – Adds element to the end of the array .reverse() – Reverses the array .sort() - Sorts the Array Remember Stacks Web-Based Systems - Misbhauddin

Web-Based Systems - Misbhauddin Displaying Arrays Display an Array Use for loop – for(var i=0; i<array-name.length;i++) Use Join Use for loop again – for(var i in array-name) Web-Based Systems - Misbhauddin

Web-Based Systems - Misbhauddin For Loop Variation for(var i=0; i<array-name.length; i++) Can loop from any point to any other point in the given array. Starting point is the initialization Ending point is the condition satisfaction for(var i in array-name) Used when you want to loop the entire array The value of i goes from 0 to the length-1 of the array Web-Based Systems - Misbhauddin

Web-Based Systems - Misbhauddin Arrays: Exercise Download the 4.2_Exercise_Instruction.pdf file. Download the decode.html file Follow the instructions from the PDF file and complete the exercise Web-Based Systems - Misbhauddin