What's wrong with Multidimensional Array?

Discussion in 'Javascript' started by Dominik, Feb 19, 2012.

  1. Dominik

    Dominik Guest

    --- Example 1
    var myarray=[[],[]];
    myarray[0][1]="NA"
    print(myarray[0][1]); // output "NA"

    --- Example 2
    var myarray=[[],[]];
    for (var x = 0; x < 5; x++) {
    for (var y = 0; y < 5; y++) {
    myarray[x][y]=0;
    }
    }

    for (var x = 0; x < 5; x++)
    print(myarray[x]); // output error myarray[x] is undefined !?!

    What's wrong with example 2 ????
     
    Dominik, Feb 19, 2012
    #1
    1. Advertisements

  2. Dominik

    Dominik Guest

    --- Example 1.1
    var myarray=[[],[]];
    myarray[10][10]="NA"
    print(myarray[10][10]); // output error myarray[10] is undefined

    OMG What a mistake-a to make-a. :)
    Thank you!

    [snip]
    OK, I see it now.
    But I'm curius, is it possible to create empty multidimensional array in
    advance?
     
    Dominik, Feb 19, 2012
    #2
    1. Advertisements

  3. Dominik

    Dominik Guest

    Thank you very much for your help. :)
     
    Dominik, Feb 19, 2012
    #3
  4. Given that, according to my current research, Array comprehension is *only*
    supported in (Mozilla) JavaScript 1.7 and later, I do not think it deserves
    the attribute "portable" at all.


    PointedEars
     
    Thomas 'PointedEars' Lahn, Feb 20, 2012
    #4
  5. Dominik

    Evertjan. Guest

    Thomas 'PointedEars' Lahn wrote on 20 feb 2012 in comp.lang.javascript:
    I fail to comprehend the meaning of such atributable comprehension, Thomas.

    Could you divulge?
     
    Evertjan., Feb 20, 2012
    #5
  6. In comp.lang.javascript message <irp1k7puv7pgmuhuuhnpovq6dolg7pubea@4ax.
    One can assign a value to a variable which does not already exist.

    For counting purposes, it would be useful to be able to increment a
    variable which currently is value=undefined or is non-existent, with the
    pre-increment value taken as either 0 or "", depending on the nature of
    the increment. Possibly with X+++ and X ++= 7.
     
    Dr J R Stockton, Feb 20, 2012
    #6
  7. Dominik

    Scott Sauyet Guest

    <https://developer.mozilla.org/en/JavaScript/Guide/
    Predefined_Core_Objects#Array_comprehensions>

    -- Scott
     
    Scott Sauyet, Feb 20, 2012
    #7
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.