
Data Structure

This illustrates a data structure, a means of storing data within a program.

You may see other such structures in the Data Structures category.
Get two integers from the user, then create a two-dimensional array where the two dimensions have the sizes given by those numbers, and which can be accessed in the most natural way possible. Write some element of that array, and then output that element. Finally destroy the array if not done by the language itself.

var width = Number(prompt("Enter width: "));
var height = Number(prompt("Enter height: "));
 
//make 2D array
var arr = new Array(height);
 
for (var i = 0; i < h; i++) {
  arr[i] = new Array(width);
}
 
//set value of element
a[0][0] = 'foo';
//print value of element
console.log('arr[0][0] = ' + arr[0][0]);
 
//cleanup array
arr = void(0);