Objects: Inside Javascript by Steven Holzner

The notes found on these pages all reference the textbook given above. Unless otherwise stated, the citation of the information on these web pages is that text.


There are many built-in objects and arrays in Javascript. Each object includes numerous methods. You should have seen date and timeout, but here are samples for you:


The string object has many methods/functions for you to use. Although it is not usually necessary, you can create a String object with the new operator


Arrays revisited. Users can declare arrays or use builtin arrays


2 dimensional arrays

To create 2D arrays, you need an array where each element of the array is an array (think table where each row of a table is an array)
This can be done via a var statement or via a loop in Javascript.
A 4 x 5 example:

var twoDimArray = [new Array(5), new Array(5), new Array(5), new Array(5)]
Or:
var twoDimArray = new Array(4);
for (i=0; i < 4; i++)
  twoDimArray[i]=new Array(5);

Your turn to try this!
Write a javascript program that
  1. prompts the user for two integers (no errror checking)
    numRows
    numCols
  2. creates a 2D array with the appropriate sizes
  3. sets each element of the 2D array to be the product of its rowNum and colNum
  4. Debug the code using alerts!
Now, add the code you have written to Friday's table generation code