Jump to content

[SOLVED] JavaScript and multidimensional arrays


rhyspaterson

Recommended Posts

Hey guys,

 

I have an array as follows:

 

var floor_array = new Array(5);
for (var i = 0; i < 5; i++) {
	floor_array[i] = [' ', ' ', ' '];
}

floor_array[0][0] = "ground";
floor_array[0][1] = "Printer Status - Ground Floor";
floor_array[0][2] = "Ground Floor";
floor_array[1][0] = "one";
floor_array[1][1] = "Printer Status - Level One";
floor_array[1][2] = "First Floor";	
floor_array[2][0] = "two";
floor_array[2][1] = "Printer Status - Level Two";
floor_array[2][2] = "Second Floor";	
floor_array[3][0] = "three";
floor_array[3][1] = "Printer Status - Level Three";
floor_array[3][2] = "Thrid Floor";	
floor_array[4][0] = "four";
floor_array[4][1] = "Printer Status - Level Four";
floor_array[4][2] = "Fourth Floor";

 

Is there a quicker way to add all the data into array (the second section)? Or do i have to define each entry each time..? Was looking for something like:

 

floor_array[0][] = "ground","Printer Status - Ground Floor","Ground Floor";

 

Thanks in advance.

Here you go:

 

    var floor_array = [
        ["ground", "Printer Status - Ground Floor", "Ground Floor"],
        ["one", "Printer Status - Level One", "First Floor"],
        ["two", "Printer Status - Level Two", "Second Floor"],
        ["three", "Printer Status - Level Three", "Thrid Floor"],
        ["four", "Printer Status - Level Four", "Fourth Floor"]
    ];

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.