Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. ARRAY auswerten

    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

    ARRAY auswerten

    This topic has been deleted. Only users with topic management privileges can see it.
    • P
      Pat last edited by

      Ich stehe gerade auf den Schlauch.
      Ich habe ein Array mit zahlen [1,2,3,4,5,6,7,8,9,10]

      Nun will ich das überprüfen ob alle Zahlen im Array >= 10 sind.

      Wie stelle ich das am schlausten an ?

      bsp die ich schon Probiert habe:

      function abfrage(a_array = []){
         if (a_array.some(groesserzehn)){
              bla
         }
          function groesserzehn(level) {
              return level >= 10;
          }
      }
      

      Hier bekomme ich ein true sobald eine zahl größer 10 ist

      for (let i = 0; i<i_länge; i++){
          if (a_array[i] >= 10 ) {
              variable = true;
              break
           }
      

      Hier sobald er die erste 10 gefunden hat und ohne break wenn die letzte zahl eine 10 ist und alle anderen nicht bekomme ich auch ein true.

      paul53 OliverIO 2 Replies Last reply Reply Quote 0
      • paul53
        paul53 @Pat last edited by

        @pat sagte: ob alle Zahlen im Array >= 10 sind.

        function abfrage(arr) {
           for(let i = 0; i < arr.length; i++) {
              if(arr[i] < 10) return false;
           }
           return true;
        }
        
        1 Reply Last reply Reply Quote 0
        • OliverIO
          OliverIO @Pat last edited by OliverIO

          @pat

          oder noch kürzer:

          Every prüft ob alle Elemente eine Bedingung erfüllen und gibt dann true oder false aus.

          [1,2,3,4,5,6,7,8,9,10].every(el => el >= 10 )
          

          https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Array/every

          Es gibt dann noch some, welches prüft, ob mindestens ein Element eine Bedingung erfüllt.

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

          Support us

          ioBroker
          Community Adapters
          Donate

          909
          Online

          31.8k
          Users

          80.0k
          Topics

          1.3m
          Posts

          3
          3
          283
          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