Lab 14: JavaScript Arrays

In this lab, you will work with JavaScript arrays.

Objectives:

Part 1: JavaScript Arrays

Steps:

  1. Use File - Close All to close all open editing windows.

  2. In RAD, create a new Dynamic Web Project named Lab14Web associated with Lab14EAR.

  3. In the WebContent folder, create an HTML named arrays.html and a JavaScript that creates an array containing all of the months of the year. Then write a loop that prints all of the month strings to the document.

  4. The document.getElementsByTagName() method returns an "array-like" object containing a list of all of the elements in the document with a given tag name. You can treat the array-like object just like an array, indexing as normal.

    Create a new file, paragraphs.html that contains several HTML "p" elements with text in them. In a script at the end of the body element, use getElementsByTagName() to retrieve the array-like list of "p" elements, then iterate the array-like object, concatenating the text from each paragraph into a string. Then use alert() to display the string.

  5. Copy arrays.html to a new file, array-methods.html.

    Use the array functions to do the following: