paul: Mehrdimensionale arrays

hi zusammen

ist es mit javascript nicht möglich mehrdimensionale arrays zu machen???

so geht es zumindest nicht:

var test = new Array();

test[0][0] = 1;
test[0][1] = 2;
test[0][2] = 3;

alert(test[0][1]);

greeez paul

  1. Hi,

    var test = new Array();
    test[0][0] = 1;

    var test    = new Array();
    var test[0] = new Array();

    Gruesse, Joachim

    --
    Am Ende wird alles gut.
  2. gruss paul

    ...
    ist es mit javascript nicht möglich mehrdimensionale arrays zu machen???
    ...

    array-objekte lassen sich nicht nur ueber den "Array"-konstruktor
       erzeugen. man kann sich auch der literalschreibweise fuer arrays
       bedienen, die es einem ermoeglicht, komplexe strukturen in einem
       einzigen ausdruck zu definieren.

    var arr;
       arr = new Array(); // "new"-operator zusammen mit "Array"-konstruktor
       // ist aequivalent zu:
       arr = []; // das literal "[]" steht demnach fuer ein leeres array-objekt;

    var d1Arr = ["m1","m2","m3","m4"]; // vektor: 4 eintraege;

    var d2Arr = [ // 2d-matrix: 4x4-eintraege;
         ["m1n1","m1n2","m1n3","m1n4"],
         ["m2n1","m2n2","m2n3","m2n4"],
         ["m3n1","m3n2","m3n3","m3n4"],
         ["m4n1","m4n2","m4n3","m4n4"]
       ];

    var d3Arr = [ // 3d-matrix: 4x4x4-eintraege;
         [
           ["m1n1l1","m1n1l2","m1n1l3","m1n1l4"],
           ["m1n2l1","m1n2l2","m1n2l3","m1n2l4"],
           ["m1n3l1","m1n3l2","m1n3l3","m1n3l4"],
           ["m1n4l1","m1n4l2","m1n4l3","m1n4l4"]
         ],
         [
           ["m2n1l1","m2n1l2","m2n1l3","m2n1l4"],
           ["m2n2l1","m2n2l2","m2n2l3","m2n2l4"],
           ["m2n3l1","m2n3l2","m2n3l3","m2n3l4"],
           ["m2n4l1","m2n4l2","m2n4l3","m2n4l4"]
         ],
         [
           ["m3n1l1","m3n1l2","m3n1l3","m3n1l4"],
           ["m3n2l1","m3n2l2","m3n2l3","m3n2l4"],
           ["m3n3l1","m3n3l2","m3n3l3","m3n3l4"],
           ["m3n4l1","m3n4l2","m3n4l3","m3n4l4"]
         ],
         [
           ["m4n1l1","m4n1l2","m4n1l3","m4n1l4"],
           ["m4n2l1","m4n2l2","m4n2l3","m4n2l4"],
           ["m4n3l1","m4n3l2","m4n3l3","m4n3l4"],
           ["m4n4l1","m4n4l2","m4n4l3","m4n4l4"]
         ]
       ];

    //oder kurz:
       d1Arr=["m1","m2","m3","m4"];
       d2Arr=[["m1n1","m1n2","m1n3","m1n4"],["m2n1","m2n2","m2n3","m2n4"],["m3n1","m3n2","m3n3","m3n4"],["m4n1","m4n2","m4n3","m4n4"]];
       d3Arr=[[["m1n1l1","m1n1l2","m1n1l3","m1n1l4"],["m1n2l1","m1n2l2","m1n2l3","m1n2l4"],["m1n3l1","m1n3l2","m1n3l3","m1n3l4"],["m1n4l1","m1n4l2","m1n4l3","m1n4l4"]],[["m2n1l1","m2n1l2","m2n1l3","m2n1l4"],["m2n2l1","m2n2l2","m2n2l3","m2n2l4"],["m2n3l1","m2n3l2","m2n3l3","m2n3l4"],["m2n4l1","m2n4l2","m2n4l3","m2n4l4"]],[["m3n1l1","m3n1l2","m3n1l3","m3n1l4"],["m3n2l1","m3n2l2","m3n2l3","m3n2l4"],["m3n3l1","m3n3l2","m3n3l3","m3n3l4"],["m3n4l1","m3n4l2","m3n4l3","m3n4l4"]],[["m4n1l1","m4n1l2","m4n1l3","m4n1l4"],["m4n2l1","m4n2l2","m4n2l3","m4n2l4"],["m4n3l1","m4n3l2","m4n3l3","m4n3l4"],["m4n4l1","m4n4l2","m4n4l3","m4n4l4"]]];

    forumslinks zu objektliteralen:

    - objekt-literale als "jsDatenbanken" vom 15. 12. 2003,
       - literalschreibweise komplexer objekte: JSON - http://json.org/ vom 17. 08. 2004,
       - Doppelpunkt notation vom 23. 10. 2004,

    link zu "JSON - JavaScript Object Notation" von Mr. Douglas Crockford.

    by(t)e by(t)e - peterS. - pseliger@gmx.net

    --
    "Because objects in JavaScript are so flexible, you will want to think differently about class hierarchies.
    Deep hierarchies are inappropriate. Shallow hierarchies are efficient and expressive." - Douglas Crockford
    ie:( fl:) br:> va:( ls:& fo:) rl:| n3;} n4:} ss:} de:µ js:} mo:? zu:]