Results 1 to 6 of 6

Thread: multidimensional arrays in javascript (resolved)

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2002
    Posts
    638

    multidimensional arrays in javascript (resolved)

    i know that to create multidimensional arrays in javascript you have to create an array of arrays, seeing as it doesn't support them properly. so, if i wanted to create a 4x500 array like this:

    Code:
    Col0    Col1    Col2    Col3
    Row0    Row0    Row0    Row0
    Row1    Row1    Row1    Row1
    Row2    Row2    Row2    Row2
    ....    ....    ....    ....
    Row499  Row499  Row499  Row499
    would i have to do this:

    Code:
    var arrStuff = new Array(new Array(3), new Array(3), new Array(3), new Array(3)...500 times)
    if so, bugger that!
    Last edited by tr0n; Jul 31st, 2002 at 08:19 AM.

  2. #2
    Hyperactive Member bsw2112's Avatar
    Join Date
    Nov 2001
    Location
    ottawa, canada
    Posts
    292
    maybe you can do something like this

    Code:
    <html><head>
    
    <script>
    
    function createArray() 
    {
    	var arrStuff = new Array();
    	for (i=0;i<500;i++)
    	{
    		arrStuff[i] = new Array();
    	}
    	//populate
    	
    	for (i=0;i<500;i++)
    	{
    		for (x=0;x<4;x++)
    		{
    			arrStuff[i][x] = "hello"
    		}
    	}
    	alert(arrStuff[50][3]);
    }
    </script>
    </head>
    <body>
    <a href ="#" onClick="createArray()">click</a>
    </body>
    </html>
    i am not sure if the logic is correct

    regards

    bsw2112

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2002
    Posts
    638
    thanks, i'll try playing around with that

  4. #4
    Hyperactive Member progressive's Avatar
    Join Date
    Sep 2001
    Location
    Manchester, UK
    Posts
    404
    Why can't you have an array
    like:-

    my_array = new Array(new Array(499), new Array(499), new Array(499), new Array(499))

    visualised like:

    row0, 0 - 499
    row1, 0 - 499
    row2, 0 - 499
    row3, 0-499

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2002
    Posts
    638
    yeah, i tried that, but that ended up creating an array like this:

    row0,0 row0,1 row0,2 row0,3.....row0,499
    row1,0 row1,1 row1,2 row1,3.....row1,499

    rather than

    row0,0 row0,1 row0,2 row0,3
    row1,0 row1,1 row1,2 row1,3
    ...
    row499,0 row499,1 row499,2 row499 3

  6. #6
    Hyperactive Member progressive's Avatar
    Join Date
    Sep 2001
    Location
    Manchester, UK
    Posts
    404
    Ok, I undertsand now what you where trying to do, after helping you with your other thread !

    How did you get on with Math.round ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width