Skip to content
  • Home
  • Aktuell
  • Tags
  • 0 Ungelesen 0
  • Kategorien
  • Unreplied
  • Beliebt
  • GitHub
  • Docu
  • Hilfe
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Standard: (Kein Skin)
  • Kein Skin
Einklappen
ioBroker Logo

Community Forum

donate donate
  1. ioBroker Community Home
  2. Deutsch
  3. Skripten / Logik
  4. JavaScript
  5. Mehrdimensionale Arrays

NEWS

  • UPDATE 31.10.: Amazon Alexa - ioBroker Skill läuft aus ?
    apollon77A
    apollon77
    48
    3
    8.7k

  • Monatsrückblick – September 2025
    BluefoxB
    Bluefox
    13
    1
    2.2k

  • Neues Video "KI im Smart Home" - ioBroker plus n8n
    BluefoxB
    Bluefox
    16
    1
    3.1k

Mehrdimensionale Arrays

Geplant Angeheftet Gesperrt Verschoben JavaScript
javascript
13 Beiträge 5 Kommentatoren 2.4k Aufrufe 5 Watching
  • Älteste zuerst
  • Neuste zuerst
  • Meiste Stimmen
Antworten
  • In einem neuen Thema antworten
Anmelden zum Antworten
Dieses Thema wurde gelöscht. Nur Nutzer mit entsprechenden Rechten können es sehen.
  • G Offline
    G Offline
    Georgius
    schrieb am zuletzt editiert von
    #4

    Danke, diese Darstellung hab ich schon oft gefunde. Aber irgendwie hilft sie mir nicht weiter. Stehe wohl auf der Leitung.

    Der ganze Teil mit Array [0][0] = Text gehört in eine Schleife. Ist auch kein Problem.

    Was gehört jetzt in die Definiton?

    Var Arrayname = []
    For a ....
    Arrayname [a]= []
    For b ...
    Arraymame [a][b] = was auch immer
    }
    }

    Ich weiß, ist kein wirkliches JS.

    PeoplesP AsgothianA 2 Antworten Letzte Antwort
    0
    • G Georgius

      Danke, diese Darstellung hab ich schon oft gefunde. Aber irgendwie hilft sie mir nicht weiter. Stehe wohl auf der Leitung.

      Der ganze Teil mit Array [0][0] = Text gehört in eine Schleife. Ist auch kein Problem.

      Was gehört jetzt in die Definiton?

      Var Arrayname = []
      For a ....
      Arrayname [a]= []
      For b ...
      Arraymame [a][b] = was auch immer
      }
      }

      Ich weiß, ist kein wirkliches JS.

      PeoplesP Offline
      PeoplesP Offline
      Peoples
      schrieb am zuletzt editiert von Peoples
      #5

      @Georgius
      Gib mir doch Mal mehr Infos was du versuchst umzusetzen. Dann kann man da ja Mal versuchen was basteln :wink:

      Btw. Vielleicht hilft dir auch das ein wenig:
      Link Text

      Das war das Backup Script bevor der Adapter gebaut wurde und da habe ich das genutzt

      Ich beantworte keine Fragen zu Themen via PN

      1 Antwort Letzte Antwort
      0
      • G Georgius

        Danke, diese Darstellung hab ich schon oft gefunde. Aber irgendwie hilft sie mir nicht weiter. Stehe wohl auf der Leitung.

        Der ganze Teil mit Array [0][0] = Text gehört in eine Schleife. Ist auch kein Problem.

        Was gehört jetzt in die Definiton?

        Var Arrayname = []
        For a ....
        Arrayname [a]= []
        For b ...
        Arraymame [a][b] = was auch immer
        }
        }

        Ich weiß, ist kein wirkliches JS.

        AsgothianA Offline
        AsgothianA Offline
        Asgothian
        Developer
        schrieb am zuletzt editiert von Asgothian
        #6

        @Georgius sagte in Mehrdimensionale Arrays:

        Danke, diese Darstellung hab ich schon oft gefunde. Aber irgendwie hilft sie mir nicht weiter. Stehe wohl auf der Leitung.

        Der ganze Teil mit Array [0][0] = Text gehört in eine Schleife. Ist auch kein Problem.

        Was gehört jetzt in die Definiton?

        Das was du geschrieben hast war soweit gar nicht so schlecht. Sieht man besser mit code tags :

        var Arrayname = []
        for (let a =0;a<firstdimension; 1) {
          Arrayname [a]= []
          for (let b=0;b<seconddimension; 1) {
            Arraymame [a][b] = was auch immer
          }
        }
        

        Damit ist Arrayname als Array definiert. Das es ein mehrdimensionales Array ist wird in der Deklaration nicht hinterlegt. Bei JS sind arrays aber in der Grösse nicht definiert.. Du kannst also folgendes machen:

        function setarray(myarray,i,j, value) {
          if (typeof(myarray) != "object")  { 
            array = [] 
          }
          if (typeof(myarray[i]) != "object")  { 
             myarray[i] = []; 
          }
          myarray[i][j] = value;
          return myarray
        }
        

        A.

        ioBroker auf RPi4 - Hardware soweit wie möglich via Zigbee.
        "Shit don't work" ist keine Fehlermeldung, sondern ein Fluch.

        paul53P 1 Antwort Letzte Antwort
        0
        • AsgothianA Asgothian

          @Georgius sagte in Mehrdimensionale Arrays:

          Danke, diese Darstellung hab ich schon oft gefunde. Aber irgendwie hilft sie mir nicht weiter. Stehe wohl auf der Leitung.

          Der ganze Teil mit Array [0][0] = Text gehört in eine Schleife. Ist auch kein Problem.

          Was gehört jetzt in die Definiton?

          Das was du geschrieben hast war soweit gar nicht so schlecht. Sieht man besser mit code tags :

          var Arrayname = []
          for (let a =0;a<firstdimension; 1) {
            Arrayname [a]= []
            for (let b=0;b<seconddimension; 1) {
              Arraymame [a][b] = was auch immer
            }
          }
          

          Damit ist Arrayname als Array definiert. Das es ein mehrdimensionales Array ist wird in der Deklaration nicht hinterlegt. Bei JS sind arrays aber in der Grösse nicht definiert.. Du kannst also folgendes machen:

          function setarray(myarray,i,j, value) {
            if (typeof(myarray) != "object")  { 
              array = [] 
            }
            if (typeof(myarray[i]) != "object")  { 
               myarray[i] = []; 
            }
            myarray[i][j] = value;
            return myarray
          }
          

          A.

          paul53P Offline
          paul53P Offline
          paul53
          schrieb am zuletzt editiert von
          #7

          @Asgothian typeof ist keine Funktion.

          Bitte verzichtet auf Chat-Nachrichten, denn die Handhabung ist grauenhaft !
          Produktiv: RPi 2 mit S.USV, HM-MOD-RPI und SLC-USB-Stick mit root fs

          AsgothianA 1 Antwort Letzte Antwort
          0
          • paul53P paul53

            @Asgothian typeof ist keine Funktion.

            AsgothianA Offline
            AsgothianA Offline
            Asgothian
            Developer
            schrieb am zuletzt editiert von Asgothian
            #8

            @paul53 sagte in Mehrdimensionale Arrays:

            @Asgothian typeof ist keine Funktion.

            Siehe Hier:

            The typeof operator returns the type of the argument. It’s useful when we want to process values of different types differently or just want to do a quick check.

            It supports two forms of syntax:

            As an operator: typeof x.
            As a function: typeof(x).

            (von javascript.info/types)

            ioBroker auf RPi4 - Hardware soweit wie möglich via Zigbee.
            "Shit don't work" ist keine Fehlermeldung, sondern ein Fluch.

            paul53P 1 Antwort Letzte Antwort
            1
            • AsgothianA Asgothian

              @paul53 sagte in Mehrdimensionale Arrays:

              @Asgothian typeof ist keine Funktion.

              Siehe Hier:

              The typeof operator returns the type of the argument. It’s useful when we want to process values of different types differently or just want to do a quick check.

              It supports two forms of syntax:

              As an operator: typeof x.
              As a function: typeof(x).

              (von javascript.info/types)

              paul53P Offline
              paul53P Offline
              paul53
              schrieb am zuletzt editiert von
              #9

              @Asgothian sagte:

              It supports two forms of syntax:

              Danke, das wusste ich noch nicht.

              Bitte verzichtet auf Chat-Nachrichten, denn die Handhabung ist grauenhaft !
              Produktiv: RPi 2 mit S.USV, HM-MOD-RPI und SLC-USB-Stick mit root fs

              1 Antwort Letzte Antwort
              0
              • G Offline
                G Offline
                Georgius
                schrieb am zuletzt editiert von Georgius
                #10

                Wie gesagt, bin absoluter Anfänger in JS. )Amiga Basic hab ich einigermaßen gekonnt). Wie ist der Aufruf für die Funktion von Asgothian?
                Konkret, wie muß "myarrray" übergeben werden?

                1 Antwort Letzte Antwort
                0
                • G Offline
                  G Offline
                  Georgius
                  schrieb am zuletzt editiert von Georgius
                  #11

                  Irgendwie komm ich nicht weiter.

                  Mein Programm bisher

                  
                  var tankstelle;
                  const id=0;
                  const namen=1;
                  const preis=2;
                  const adresse1=3;
                  const adresse2=4;
                  const dist=5;
                  const lon = 6;
                  const lat = 7;
                  
                  if (typeof(tankstelle) != "object")  { 
                      tankstelle = [] 
                    }
                    if (typeof(tankstelle[1]) != "object")  { 
                       tankstelle[1] = []; 
                    }
                  
                  on({id: 'javascript.0.Sprit_t.Sprit_JSON'/*Sprit JSON*/, change: 'any'}, function(obj)
                   {
                      
                      var index = 0;
                      var gasStation = JSON.parse(obj.state.val); 
                   var start =  "javascript.0.Sprit.Tankstelle_";
                      
                     for (index = 0; index < gasStation.length; ++index) {
                          tankstelle[index][id]= (gasStation[index].id);
                          tankstelle[index][namen]= (gasStation[index].name);
                          tankstelle[index][preis]= (gasStation[index].prices[0].amount).toString().replace(".",",");
                          tankstelle[index][adresse1]= (gasStation[index].location.address);
                          tankstelle[index][adresse2]= (gasStation[index].location.postalCode + " "+ gasStation[index].location.city);
                          tankstelle[index][dist]= (gasStation[index].distance);
                          tankstelle[index][lon]= (gasStation[index].longitude);
                          tankstelle[index][lat]= (gasStation[index].latitude);
                  
                      };
                     
                  
                  
                   });
                  

                  Ich bekomme beim durchlaufen den Fehler

                  00:16:36.972	error	javascript.0 at Object.<anonymous> (script.js.common.Sonstiges.Tanken:32:30)
                  

                  30 ist das "=" in

                   tankstelle[index][id]= (gasStation[index].id);
                  

                  Edit: einen Fehler gefunden und hier ausgebessert. Hauptproblem besteht weiter

                  AsgothianA 1 Antwort Letzte Antwort
                  0
                  • G Georgius

                    Irgendwie komm ich nicht weiter.

                    Mein Programm bisher

                    
                    var tankstelle;
                    const id=0;
                    const namen=1;
                    const preis=2;
                    const adresse1=3;
                    const adresse2=4;
                    const dist=5;
                    const lon = 6;
                    const lat = 7;
                    
                    if (typeof(tankstelle) != "object")  { 
                        tankstelle = [] 
                      }
                      if (typeof(tankstelle[1]) != "object")  { 
                         tankstelle[1] = []; 
                      }
                    
                    on({id: 'javascript.0.Sprit_t.Sprit_JSON'/*Sprit JSON*/, change: 'any'}, function(obj)
                     {
                        
                        var index = 0;
                        var gasStation = JSON.parse(obj.state.val); 
                     var start =  "javascript.0.Sprit.Tankstelle_";
                        
                       for (index = 0; index < gasStation.length; ++index) {
                            tankstelle[index][id]= (gasStation[index].id);
                            tankstelle[index][namen]= (gasStation[index].name);
                            tankstelle[index][preis]= (gasStation[index].prices[0].amount).toString().replace(".",",");
                            tankstelle[index][adresse1]= (gasStation[index].location.address);
                            tankstelle[index][adresse2]= (gasStation[index].location.postalCode + " "+ gasStation[index].location.city);
                            tankstelle[index][dist]= (gasStation[index].distance);
                            tankstelle[index][lon]= (gasStation[index].longitude);
                            tankstelle[index][lat]= (gasStation[index].latitude);
                    
                        };
                       
                    
                    
                     });
                    

                    Ich bekomme beim durchlaufen den Fehler

                    00:16:36.972	error	javascript.0 at Object.<anonymous> (script.js.common.Sonstiges.Tanken:32:30)
                    

                    30 ist das "=" in

                     tankstelle[index][id]= (gasStation[index].id);
                    

                    Edit: einen Fehler gefunden und hier ausgebessert. Hauptproblem besteht weiter

                    AsgothianA Offline
                    AsgothianA Offline
                    Asgothian
                    Developer
                    schrieb am zuletzt editiert von Asgothian
                    #12

                    @Georgius
                    Der Fehler ist, das du nur die erste Zeile des Arrays initialisierst.
                    (Zeile 16: Tankstelle[1] = [];)
                    Schon wenn index 2 wird versuchst du in ein nicht initialisiertes Objekt einen Wert einzutragen.

                    Ich würde in Zeile 27 ein
                    tankstelle[index] = [];
                    einfügen.

                    Was noch bleibt ist die Frage ob das JSON immer die gleiche Anzahl Tankstellen beinhaltet. Wenn ja ist alles gut. Wenn nein, dann kann es sein das alte Daten am Ende der Tabelle erhalten bleiben.

                    ioBroker auf RPi4 - Hardware soweit wie möglich via Zigbee.
                    "Shit don't work" ist keine Fehlermeldung, sondern ein Fluch.

                    1 Antwort Letzte Antwort
                    0
                    • G Offline
                      G Offline
                      Georgius
                      schrieb am zuletzt editiert von
                      #13

                      Danke, jetzt funktioniert es. Das Arraymodell ist irgendwie anders als ich sie kenne.

                      Auch danke für den Hinweis mit der Arraygröße..

                      1 Antwort Letzte Antwort
                      0
                      Antworten
                      • In einem neuen Thema antworten
                      Anmelden zum Antworten
                      • Älteste zuerst
                      • Neuste zuerst
                      • Meiste Stimmen


                      Support us

                      ioBroker
                      Community Adapters
                      Donate

                      372

                      Online

                      32.4k

                      Benutzer

                      81.5k

                      Themen

                      1.3m

                      Beiträge
                      Community
                      Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen | Einwilligungseinstellungen
                      ioBroker Community 2014-2025
                      logo
                      • Anmelden

                      • Du hast noch kein Konto? Registrieren

                      • Anmelden oder registrieren, um zu suchen
                      • Erster Beitrag
                        Letzter Beitrag
                      0
                      • Home
                      • Aktuell
                      • Tags
                      • Ungelesen 0
                      • Kategorien
                      • Unreplied
                      • Beliebt
                      • GitHub
                      • Docu
                      • Hilfe