lecture17

lecture17 - PIC 40A Lecture 17: JavaScript Arrays,...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
PIC 40A Lecture 17: JavaScript Arrays, Functions, Constructors
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
JavaScript Array Object • an array is an object • contains data elements in sequential order • elements need not be of the same type • elements can be primitive values or object references (possibly functions or other arrays) • has dynamic length
Background image of page 2
Array Object Creation • created via the Array constructor : // creates an empty array of length 3 var my_array = new Array(3); // creates an array of length 4 var a2 = new Array(“7”, 1, new Date(), true); • created via an Array literal : var a3 = [“7”, 1, new Date(), false];
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Array Objects • lowest index at 0 • length of an array = highest index to which an element has been assigned + 1 • can set the length of an array using length property: a3.length = 3 ; • only assigned elements occupy space • all array elements are allocated dynamically on the heap
Background image of page 4
Array Object Methods • join(delimiter) – converts all elements to strings and then concatenates them to a single string, separated by given delimiter • reverse() – reverses order of elements • sort() – sorts array elements as strings, not numbers • concat(a1, a2, . .) – returns a new array that joins the given arrays to the calling array • slice() – returns part of an array
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 22

lecture17 - PIC 40A Lecture 17: JavaScript Arrays,...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online