ARRAYS MIT-AITI Copyright 2001.

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

Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Arrays.
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.
Lecture 3 Term 2 23/1/12. Arrays You can create an array with the Array() constructor and the new operator. There are three ways to invoke the Array()
25-Jun-15 JavaScript Language Fundamentals II. 2 Exception handling, I Exception handling in JavaScript is almost the same as in Java throw expression.
JavaScript, Third Edition
OBJECTS MIT-AITI copyright Introduction Object and Properties Constructors and Methods Prototypes and Inheritance Object-Oriented JavaScript Objects.
Programming Concepts MIT - AITI. Variables l A variable is a name associated with a piece of data l Variables allow you to store and manipulate data in.
CSE 341 Lecture 24 JavaScript arrays and objects slides created by Marty Stepp
CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Using Arrays in JavaScript.
 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.
CNIT 133 Interactive Web Pags – JavaScript and AJAX Arrays.
Python Lists and Such CS 4320, SPRING List Functions len(s) is the length of list s s + t is the concatenation of lists s and t s.append(x) adds.
Java Script: Arrays (Chapter 11 in [2]). 2 Outline Introduction Introduction Arrays Arrays Declaring and Allocating Arrays Declaring and Allocating Arrays.
Built-in Data Structures in Python An Introduction.
Functions and Arrays. Predefined Functions eval(condition) –Evaluates (executes) JavaScript syntax –Eval returns an undefined value parseInt(string) and.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 8 Lists and Tuples.
Project 1: Using Arrays and Manipulating Strings Essentials for Design JavaScript Level Two Michael Brooks.
Chapter 5: Arrays in JavaScript 5.1 Basic Array Properties 5.2 Some Operations on Arrays 5.3 Simulating Multidimensional Arrays 5.4 Using Arrays to Access.
Unit 12 JavaScript Arrays Instructor: Brent Presley.
CNIT 133 Interactive Web Pags – JavaScript and AJAX Objects.
LISTS and TUPLES. Topics Sequences Introduction to Lists List Slicing Finding Items in Lists with the in Operator List Methods and Useful Built-in Functions.
MIT-AITI: Functions Defining and Invoking Functions Functions as Data Function Scope: The call Object Function Arguments: The arguments objects Function.
ECA 225 Applied Interactive Programming ECA 225 Applied Online Programming javascript arrays.
JavaScript and Ajax (JavaScript Arrays) Week 5 Web site:
Chapter 5 Murach's JavaScript and jQuery, C1© 2012, Mike Murach & Associates, Inc.Slide 1.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 this week – last section on Friday. Assignment 4 is posted. Data mining: –Designing functions.
1 Agenda  Unit 8: Programs and Data. 2 Structured data - Array There are many situations where we want to apply the same processing to a collections.
Python Lists and Sequences Peter Wad Sackett. 2DTU Systems Biology, Technical University of Denmark List properties What are lists? A list is a mutable.
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.
Basic Objects. Math Object  Math.cos( x ), x in radians  Math.sqrt ( x )  Math.pow ( x, y )  Math.ceil( x )  etc.
String and Lists Dr. José M. Reyes Álamo.
Chapter 11 - JavaScript: Arrays
CGS 3066: Web Programming and Design Spring 2017
Data types: Complex types (List)
Strings, StringBuilder, and Character
Containers and Lists CIS 40 – Introduction to Programming in Python
Arrays 2/4 By Pius Nyaanga.
Basics of JavaScript Programming Language
SEEM4570 Tutorial 05: JavaScript as OOP
JavaScript Syntax and Semantics
Arrays and the ArrayList Class The ArrayList Class
Loops and Arrays.
JavaScript: Functions.
>> JavaScript: Arrays
JavaScript Functions and Arrays
Lists Part 1 Taken from notes by Dr. Neil Moore & Dr. Debby Keen
CS313D: Advanced Programming Language
JavaScript and Ajax (Expression and Operators)
The relational operators
Objectives Create an array Work with array properties and methods
Agenda Unit 8: Programs and Data.
Web Systems Development (CSC-215)
Perl Variables: Array Web Programming.
Lists in Python.
© Akhilesh Bajaj, All rights reserved.
Hw 5 Hints.
4. sequence data type Rocky K. C. Chang 16 September 2018
CS 1111 Introduction to Programming Fall 2018
JavaScript Arrays.
String and Lists Dr. José M. Reyes Álamo.
CS5220 Advanced Topics in Web Programming JavaScript Basics
Topics Sequences Introduction to Lists List Slicing
CS 1111 Introduction to Programming Spring 2019
JavaScript: Arrays.
JavaScript CS 4640 Programming Languages for Web Applications
Topics Sequences Introduction to Lists List Slicing
CGS 3066: Web Programming and Design Spring 2016
Lecture 9: JavaScript Syntax
Introduction to Computer Science
Presentation transcript:

ARRAYS MIT-AITI Copyright 2001

Array A data structure that contains numbered pieces of data. Different from associative arrays Arrays are really objects with added functionality

Array and Array Elements An array stores numbered pieces of data Each numbered datum is called an element of the array and the number assigned to it an index. The elements of the array maybe of any type. You can even store arrays as elements in another array.

Creating Arrays Arrays are created using the Array() constructor or an Array literal The above constructor can be invoked in three ways. var a = new Array();//creates new empty array var a = new Array(5 , 4, “Wassup”);//You can specify elements of array var a = new Array(10);//You can specify length of array Var a = [[1,{x:1,y:2}], [2,{x:3,y:4}]];//Array literal

Reading and Writing Elements Array elements are accessed using the [ ] operator. A reference to the array is on the left of the operator whilst a non-negative number is in the operator. value = a[7];

Adding Elements Add a new element by assigning a value to it. Arrays in JavaScript are sparse: only elements in existence have memory allocated to them.

Array Length This property specifies how many elements an array has. This property is automatically updated whenever new elements are added to the array. a = new Array(1,2,3); a.length == 3 //Evaluates to true;

Array Length usage The length property enables us to loop through elements of an array; var girls = [“Sarah”, “Selma”, “Seme”, “Kate”]; for(var i=0;i < girls.length;i++) alert(girls[i]); If the array is not contiguous the above would change to for(var i=0;i < girls.length;i++) if girls[i]alert(girls[i]);

Removing elements To delete elements from an array set the length property so that those elements that you want to delete are out of the length range. If you use the delete property the element becomes undefined but the length of the array remains the same

Array Methods join() reverse() sort() concat() slice() toString()

join() Converts all the elements of an array to a string and concatenates them. You can specify an optional string used to separate the elements in the resulting string. var a = [1,2,3] a.join(“, ”);//s == “1, 2, 3”

reverse() Reverses the order of elements in an Array. It doesn’t create a new array but rearranges the elements in the original array.

sort() Sorts the elements of an array When called with no arguments sorts the arrays in alphabetical order. Optionally you could specify a function that would be used in sorting the elements

Concat Creates and returns an array that contains the elements of the original array that concat() was invoked on followed by the arguments to concat. var a = [1,2,3]; a.concat(4,5);//[1,2,3,4,5]

Splice() Returns a slice or subarray of the specified array. Its two arguments specify the start and end of the slice to be returned. If only one argument is specified the slice returned contains all elements from the start position till end of the array