To Lecture Notes

IT 238 -- Jan 28, 2026

Review Exercises

  1. Test the array lookup operator [ ]. Answer:
    var a = ["abc", "def", "ghi", "jkl", "mno"];
    document.writeln(a[3]);
    
    Recall that array indices in JavaScript are zero-based.
  2. Explain what properties and methods are for an object.
    Answer: a property is a piece of data that is stored in an object; a method is a procedure that can be called from the object to do something.

Array Properties and Methods

Object Literals

JavaScript Object Notation (JSON)

Practice Problems

  1. Convert the JSON string defined in the Kids Data file kidsdata.js file into an array of object literals. Then print the names of the kids in the array. Answer:
    <!DOCTYPE html>
    <html lang="en">
        <head>
            <meta charset="UTF-8">
            <title>Document</title>
            <script src="kidsdata.js"></script>
            <script>
            // If JS statements are called from the head tag,
            // they must be placed in an init method that
            // is called when the page is loaded.
            function init( ) {
                var objects = JSON.parse(kids);
                for(var kid of objects) {
                    document.writeln(kid.name + "<br>");
                }
            }
            window.addEventListener("load", init);
            </script>
        </head>
        <body></body>
    </html>
    

Project 2a