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.

Link to comment
Share on other sites

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"]
    ];

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.