A Two Dimensional Array In JavaScript

LEVEL: Beginner

Whats in this post?

  1. Code
  2. Output
  3. Background and Explanation of the code

Code


To copy code: Click  View Source “View Source” on the right of this code snippet.

Background and Explanation of the code


This is a simple program which creates a 2 dimensional array in javascript and prints its contents using document.write method. Printing an empty line using document.write is not very straight forward. One way of doing the same is using <pre> tag. The <pre> tag defines preformatted text. Text in a pre element is displayed in a fixed-width font (usually Courier), and it preserves both spaces and line breaks.