Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8979607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:53:10+00:00 2026-06-15T19:53:10+00:00

I could use some guidance on specifying a dynamic multi dimensional array in javascript.

  • 0

I could use some guidance on specifying a dynamic multi dimensional array in javascript. I understand that javascript does not natively define multi dim arrays, but rather an array of an array, ie.

 var items = [[1,2],[3,4],[5,6]];

or

 var array = [[,],[,]]

or

 var a = [[1,2],[3,4]]

My issue is that I do not know the actual dimensions, and simply defining the array, as in the second example above, still does not allow for the array to go beyond two record sets. I thought there was a REDIM stmt similar to VB but have not been able to locate anything.

One additional part of my problem is that when I specify the second dimension of the array, as in the example below, the array becomes unreachable outside of the for block.

var Exforsys=new Array(4)
for (i=0; i <4; i++) {
   Exforsys[i]=new Array(4)
}

I am trying to retrieve data from my specific array like this…

 function newTest() {
        var myArray = [[],[]];
      //  myArray[] = new Array(14);

        var recCount = coordsAry.length / 15;
        var n =0;

        var i = 0;
        var s = 0;

        for (i = 0; i < recCount; i++) {
            for (s = 0; s < 15; s++) {
              //  myArray[i] = new Array(14);

                myArray[i][s] = coordsAry[n];
                n++;

              //  alert("i=" + i + " s=" + s + " Val: " + (myArray[i][s]));

            }
            // var u = 4;
            s = 0;

            alert(myArray[0][3]);
            alert(myArray[0][4]);

            alert("i=" + i + " s=" + s + " Val: " + (myArray[i][s]));              

        }

coordsAry has 105 records and is flat, {“12″,”Frank”,”564″, … etc} this has been proven. After the 2nd record is populated I get this error….

Error: Unable to set value of the property '0': object is null or undefined.

Obviously, my javascript skills are a bit rough to say the least. Any sample code would be greatly appreciated.

Thanks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:53:12+00:00Added an answer on June 15, 2026 at 7:53 pm

    You do not Dim the Array to an actual size,

    You can just set an variable on any index to whatever you want

    if you want two Dimensions you just could define an array

    var arr = []

    set an element to another array

    arr[0] = []

    and put an value inside an element in the “2nd dimension”

    arr[0][10] = 10

    You only have the elements in the “first dimension” to be an array

    You could also do things like placing arrays into arrays

    like

    var arr = []
    var arr1 = [1,2,3]
    arr[0] = arr1
    console.log(arr[0][2]) //3
    

    And if you have an array and want to push elements in an inner array just do a check if the element is defined, like

    var arr = []
    for ( var i = 0; i < 5 ; i++) {
        if(!arr[i])
            arr[i] = []
        for ( var j = 0; j < 3 ; j++)
            arr[i][j] = i + " - " + j // Or like this,
            //arr[i].push(i + " " + j) // 
    }
    console.log( arr[2][3]) // 2 - 3
    

    Given the Code you posted

    function newTest() {
        var myArray = [[],[]];
      //  myArray[] = new Array(14);
    
        var recCount = 15
        var n =0;
    
        var i = 0;
        var s = 0;
    
        for (i = 0; i < recCount; i++) {
            if(!myArray[i])
                 myArray[i] = []
            for (s = 0; s < 15; s++) {
                console.log(i)
    
              //  myArray[i] = new Array(14);
    
                myArray[i][s] = s;
                n++;
    
              //  alert("i=" + i + " s=" + s + " Val: " + (myArray[i][s]));
    
            }
            // var u = 4;
            s = 0;
    
            alert(myArray[0][3]);
            alert(myArray[0][4]);
    
            alert("i=" + i + " s=" + s + " Val: " + (myArray[i][s]));              
    
        }
    }
    newTest()
    

    This works for me

    ​

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This problem is taking me too long to fix I could use some guidance
I have a design conundrum that I could use some feedback on, so I'm
I've been struggling with rails models a bit and could use some guidance. I
I could really use some guidance on how to take this sql query to
I am brand new to this, teaching myself, and could really use some guidance.
just a few questions that I thought I could use some light on. So
I could use some guidance in how to proceed on form validation in CodeIgniter.
Could someone give me some guidance on when I should use WITH (NOLOCK) as
I could use some help with expression conversion. I have a method on a
I am really new to Ruby and could use some help with a program.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.