Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. [gelöst] hilfe bei element aus json löschen

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    [gelöst] hilfe bei element aus json löschen

    This topic has been deleted. Only users with topic management privileges can see it.
    • liv-in-sky
      liv-in-sky last edited by liv-in-sky

      kann mir bitte jemand sagen (evtl @paul53 ), wie man den ganzen block aus diesem object löscht - der ganze block von mit text : WARNUNG LEBENSMITTEL1 soll gelöscht werden

      {
      		"text": "WARNUNG Lebensmittel1 ",
      		"backgroundColor": "black",
      		"borderColor": "ligthgreen",
      		"icon": "/vis.0/armin/img/temporarily_not_available.png",
      		"iconColor": "lightgreen",
      		"fontColor": "lightgreen"
      	},
      
      [
      	{
      		"text": "WARNUNG Lebensmittel ",
      		"backgroundColor": "black",
      		"borderColor": "ligthgreen",
      		"icon": "/vis.0/armin/img/temporarily_not_available.png",
      		"iconColor": "lightgreen",
      		"fontColor": "lightgreen"
      	},
      	{
      		"text": "WARNUNG Lebensmittel1 ",
      		"backgroundColor": "black",
      		"borderColor": "ligthgreen",
      		"icon": "/vis.0/armin/img/temporarily_not_available.png",
      		"iconColor": "lightgreen",
      		"fontColor": "lightgreen"
      	},
      	{
      		"text": "WARNUNG Lebensmittel2 ",
      		"backgroundColor": "black",
      		"borderColor": "ligthgreen",
      		"icon": "/vis.0/armin/img/temporarily_not_available.png",
      		"iconColor": "lightgreen",
      		"fontColor": "lightgreen"
      	}
      ]
      

      getestet funktioniert nicht

      
        for(var i=0;i<myObj.length;i++) {
       
       if(myObj[i].text=="WARNUNG Lebensmittel1") delete myObj[i];
      
      paul53 1 Reply Last reply Reply Quote 0
      • paul53
        paul53 @liv-in-sky last edited by

        @liv-in-sky
        Versuche es mal so:

        let arr = JSON.parse(json);
        for(let i = 0; i < arr.length; i++) {
           if(arr[i].text == 'WARNUNG Lebensmittel1 ') arr.splice(i, 1);
        }
        

        Achte darauf, dass am Ende von .text ein Leerzeichen ist.

        liv-in-sky 1 Reply Last reply Reply Quote 0
        • liv-in-sky
          liv-in-sky @paul53 last edited by

          @paul53

          oh man- das hatte ich schon so ähnlich - erstmal danke dafür - das funktioniert

          jetzt aber eine stufe weiter

          das nächste probleme : alle 3 text-keys haben den selben namen "WARNUNG Lebensmittel" - also ohne 1,2,3

          wenn die schleife jetzt läuft, bleibt immer ein eintrag stehen - ich nehme an, weil ich das object ändere - die anzahl, wie oft das drinsteht kann unterschiedlich sein

          gibt es da eine elegante lösung oder lasse ich das ganze einfach zweimal hintereinander laufen (so funktioniert es)

          paul53 1 Reply Last reply Reply Quote 0
          • paul53
            paul53 @liv-in-sky last edited by paul53

            @liv-in-sky
            Versuche mal:

            for(let i = 0; i < arr.length; i++) {
               if(arr[i].text == 'WARNUNG Lebensmittel ') {
                  arr.splice(i, 1);
                  i--;
               }
            }
            
            liv-in-sky 1 Reply Last reply Reply Quote 3
            • liv-in-sky
              liv-in-sky @paul53 last edited by

              @paul53 tausend dank - das war es

              1 Reply Last reply Reply Quote 0
              • First post
                Last post

              Support us

              ioBroker
              Community Adapters
              Donate

              963
              Online

              31.8k
              Users

              80.0k
              Topics

              1.3m
              Posts

              javascript
              2
              5
              582
              Loading More Posts
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes
              Reply
              • Reply as topic
              Log in to reply
              Community
              Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
              The ioBroker Community 2014-2023
              logo