Weiter zum Inhalt
  • Home
  • Aktuell
  • Tags
  • 0 Ungelesen 0
  • Kategorien
  • Unreplied
  • Beliebt
  • GitHub
  • Docu
  • Hilfe
Skins
  • Hell
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dunkel
  • 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. [Vorlage] Hilfreiche JavaScript-Funktionen

NEWS

  • Neuer ioBroker-Blog online: Monatsrückblick März/April 2026
    BluefoxB
    Bluefox
    8
    1
    859

  • Verwendung von KI bitte immer deutlich kennzeichnen
    HomoranH
    Homoran
    10
    1
    648

  • Monatsrückblick Januar/Februar 2026 ist online!
    BluefoxB
    Bluefox
    18
    1
    1.2k

[Vorlage] Hilfreiche JavaScript-Funktionen

Geplant Angeheftet Gesperrt Verschoben JavaScript
javascript
23 Beiträge 10 Kommentatoren 13.7k Aufrufe 43 Beobachtet
  • Ä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.
  • Christoph1337C Christoph1337

    Moin zusammen,

    ich habe mal versucht ein paar der Funktionen bei mir einzufügen.

    Allerdings bekomme ich immer folgende Meldung:

    script.js.common.Array compile failed: at script.js.common.Array:256

    das komische. Das Script geht garnicht bis Zeile 256...

    Auch wenn ich dann alle Zeilen aus kommentiere habe ich dieses Problem.

    /**
     * Remove Duplicates from Array
     * Source - https://stackoverflow.com/questions/23237704/nodejs-how-to-remove-duplicates-from-array
     * @param {array} inputArray       Array to process
     * @return {array}  Array without duplicates.
     */
    
    function GlobalarrayRemoveDublicates(inputArray) {
        let uniqueArray;
        uniqueArray = inputArray.filter(function(elem, pos) {
            return inputArray.indexOf(elem) == pos;
        });
        return uniqueArray;
    }
    
    /**
     * Clean Array: Removes all falsy values: undefined, null, 0, false, NaN and "" (empty string)
     * Source: https://stackoverflow.com/questions/281264/remove-empty-elements-from-an-array-in-javascript
     * @param {array} inputArray       Array to process
     * @return {array}  Cleaned array
     */
    /*
    function GlobalcleanArray(inputArray) {
      var newArray = [];
      for (let i = 0; i < inputArray.length; i++) {
        if (inputArray[i]) {
          newArray.push(inputArray[i]);
        }
      }
      return newArray;
    }
    */
    /**
     * Removing Array element(s) by input value. 
     * @param {array}   arr             the input array
     * @param {string}  valRemove       the value to be removed
     * @param {boolean} [exact=true]    OPTIONAL: default is true. if true, it must fully match. if false, it matches also if valRemove is part of element string
     * @return {array}  the array without the element(s)
     */
    /*
    function GlobalarrayRemoveElementsByValue(arr, valRemove, exact) {
     
        if (exact === undefined) exact = true;
     
        for ( let i = 0; i < arr.length; i++){ 
            if (exact) {
                if ( arr[i] === valRemove) {
                    arr.splice(i, 1);
                    i--; // required, see https://love2dev.com/blog/javascript-remove-from-array/
                }
            } else {
                if (arr[i].indexOf(valRemove) != -1) {
                    arr.splice(i, 1);
                    i--; // see above
                }
            }
        }
        return arr;
    }
    */
    /**
     * Checks if Array or String is not undefined, null or empty.
     * 08-Sep-2019: added check for [ and ] to also catch arrays with empty strings.
     * @param inputVar - Input Array or String, Number, etc.
     * @return true if it is undefined/null/empty, false if it contains value(s)
     * Array or String containing just whitespaces or >'< or >"< or >[< or >]< is considered empty
     */
    /*
    function GlobalisLikeEmpty(inputVar) {
        if (typeof inputVar !== 'undefined' && inputVar !== null) {
            let strTemp = JSON.stringify(inputVar);
            strTemp = strTemp.replace(/\s+/g, ''); // remove all whitespaces
            strTemp = strTemp.replace(/\"+/g, "");  // remove all >"<
            strTemp = strTemp.replace(/\'+/g, "");  // remove all >'<
            strTemp = strTemp.replace(/[+/g, "");  // remove all >[<
            strTemp = strTemp.replace(/]+/g, "");  // remove all >]<
            if (strTemp !== '') {
                return false;
            } else {
                return true;
            }
        } else {
            return true;
        }
    }
    */
    
    Christoph1337C Offline
    Christoph1337C Offline
    Christoph1337
    schrieb am zuletzt editiert von
    #21

    Hab es selber gelöst:

    /** 
     * Checks if Array or String is not undefined, null or empty.
     * 08-Sep-2019: added check for [ and ] to also catch arrays with empty strings.
     * @param inputVar - Input Array or String, Number, etc.
     * @return true if it is undefined/null/empty, false if it contains value(s)
     * Array or String containing just whitespaces or >'< or >"< or >[< or >]< is considered empty
    */
    
    function GlobalIsLikeEmpty(inputVar) 
    {
        if (typeof inputVar !== 'undefined' && inputVar !== null) {
            let strTemp = JSON.stringify(inputVar);
            strTemp = strTemp.replace(/\s+/g, ''); // remove all whitespaces
            strTemp = strTemp.replace(/\"+/g, "");  // remove all >"<
            strTemp = strTemp.replace(/\'+/g, "");  // remove all >'<
            strTemp = strTemp.replace(/\[+/g, "");  // remove all >[<
            strTemp = strTemp.replace(/]+/g, "");  // remove all >]<
    
            if (strTemp !== '') {
                return false;
            } else {
                return true;
            }
        } else {
            return true;
        }
    }
    
    1 Antwort Letzte Antwort
    0
    • Christoph1337C Christoph1337

      Moin zusammen,

      ich habe mal versucht ein paar der Funktionen bei mir einzufügen.

      Allerdings bekomme ich immer folgende Meldung:

      script.js.common.Array compile failed: at script.js.common.Array:256

      das komische. Das Script geht garnicht bis Zeile 256...

      Auch wenn ich dann alle Zeilen aus kommentiere habe ich dieses Problem.

      /**
       * Remove Duplicates from Array
       * Source - https://stackoverflow.com/questions/23237704/nodejs-how-to-remove-duplicates-from-array
       * @param {array} inputArray       Array to process
       * @return {array}  Array without duplicates.
       */
      
      function GlobalarrayRemoveDublicates(inputArray) {
          let uniqueArray;
          uniqueArray = inputArray.filter(function(elem, pos) {
              return inputArray.indexOf(elem) == pos;
          });
          return uniqueArray;
      }
      
      /**
       * Clean Array: Removes all falsy values: undefined, null, 0, false, NaN and "" (empty string)
       * Source: https://stackoverflow.com/questions/281264/remove-empty-elements-from-an-array-in-javascript
       * @param {array} inputArray       Array to process
       * @return {array}  Cleaned array
       */
      /*
      function GlobalcleanArray(inputArray) {
        var newArray = [];
        for (let i = 0; i < inputArray.length; i++) {
          if (inputArray[i]) {
            newArray.push(inputArray[i]);
          }
        }
        return newArray;
      }
      */
      /**
       * Removing Array element(s) by input value. 
       * @param {array}   arr             the input array
       * @param {string}  valRemove       the value to be removed
       * @param {boolean} [exact=true]    OPTIONAL: default is true. if true, it must fully match. if false, it matches also if valRemove is part of element string
       * @return {array}  the array without the element(s)
       */
      /*
      function GlobalarrayRemoveElementsByValue(arr, valRemove, exact) {
       
          if (exact === undefined) exact = true;
       
          for ( let i = 0; i < arr.length; i++){ 
              if (exact) {
                  if ( arr[i] === valRemove) {
                      arr.splice(i, 1);
                      i--; // required, see https://love2dev.com/blog/javascript-remove-from-array/
                  }
              } else {
                  if (arr[i].indexOf(valRemove) != -1) {
                      arr.splice(i, 1);
                      i--; // see above
                  }
              }
          }
          return arr;
      }
      */
      /**
       * Checks if Array or String is not undefined, null or empty.
       * 08-Sep-2019: added check for [ and ] to also catch arrays with empty strings.
       * @param inputVar - Input Array or String, Number, etc.
       * @return true if it is undefined/null/empty, false if it contains value(s)
       * Array or String containing just whitespaces or >'< or >"< or >[< or >]< is considered empty
       */
      /*
      function GlobalisLikeEmpty(inputVar) {
          if (typeof inputVar !== 'undefined' && inputVar !== null) {
              let strTemp = JSON.stringify(inputVar);
              strTemp = strTemp.replace(/\s+/g, ''); // remove all whitespaces
              strTemp = strTemp.replace(/\"+/g, "");  // remove all >"<
              strTemp = strTemp.replace(/\'+/g, "");  // remove all >'<
              strTemp = strTemp.replace(/[+/g, "");  // remove all >[<
              strTemp = strTemp.replace(/]+/g, "");  // remove all >]<
              if (strTemp !== '') {
                  return false;
              } else {
                  return true;
              }
          } else {
              return true;
          }
      }
      */
      
      liv-in-skyL Offline
      liv-in-skyL Offline
      liv-in-sky
      schrieb am zuletzt editiert von liv-in-sky
      #22

      @christoph1337 sagte in [Vorlage] Hilfreiche JavaScript-Funktionen:

      {1}

      da sind diese {1}
      drin - da ist evtl was beim kopieren schiefgegangen

      lösche die mal raus

      nach einem gelösten Thread wäre es sinnvoll dies in der Überschrift des ersten Posts einzutragen [gelöst]-... Bitte benutzt das Voting rechts unten im Beitrag wenn er euch geholfen hat. Forum-Tools: PicPick https://picpick.app/en/download/ und ScreenToGif https://www.screentogif.com/downloads.html

      1 Antwort Letzte Antwort
      0
      • Christoph1337C Christoph1337

        Moin zusammen,

        ich habe mal versucht ein paar der Funktionen bei mir einzufügen.

        Allerdings bekomme ich immer folgende Meldung:

        script.js.common.Array compile failed: at script.js.common.Array:256

        das komische. Das Script geht garnicht bis Zeile 256...

        Auch wenn ich dann alle Zeilen aus kommentiere habe ich dieses Problem.

        /**
         * Remove Duplicates from Array
         * Source - https://stackoverflow.com/questions/23237704/nodejs-how-to-remove-duplicates-from-array
         * @param {array} inputArray       Array to process
         * @return {array}  Array without duplicates.
         */
        
        function GlobalarrayRemoveDublicates(inputArray) {
            let uniqueArray;
            uniqueArray = inputArray.filter(function(elem, pos) {
                return inputArray.indexOf(elem) == pos;
            });
            return uniqueArray;
        }
        
        /**
         * Clean Array: Removes all falsy values: undefined, null, 0, false, NaN and "" (empty string)
         * Source: https://stackoverflow.com/questions/281264/remove-empty-elements-from-an-array-in-javascript
         * @param {array} inputArray       Array to process
         * @return {array}  Cleaned array
         */
        /*
        function GlobalcleanArray(inputArray) {
          var newArray = [];
          for (let i = 0; i < inputArray.length; i++) {
            if (inputArray[i]) {
              newArray.push(inputArray[i]);
            }
          }
          return newArray;
        }
        */
        /**
         * Removing Array element(s) by input value. 
         * @param {array}   arr             the input array
         * @param {string}  valRemove       the value to be removed
         * @param {boolean} [exact=true]    OPTIONAL: default is true. if true, it must fully match. if false, it matches also if valRemove is part of element string
         * @return {array}  the array without the element(s)
         */
        /*
        function GlobalarrayRemoveElementsByValue(arr, valRemove, exact) {
         
            if (exact === undefined) exact = true;
         
            for ( let i = 0; i < arr.length; i++){ 
                if (exact) {
                    if ( arr[i] === valRemove) {
                        arr.splice(i, 1);
                        i--; // required, see https://love2dev.com/blog/javascript-remove-from-array/
                    }
                } else {
                    if (arr[i].indexOf(valRemove) != -1) {
                        arr.splice(i, 1);
                        i--; // see above
                    }
                }
            }
            return arr;
        }
        */
        /**
         * Checks if Array or String is not undefined, null or empty.
         * 08-Sep-2019: added check for [ and ] to also catch arrays with empty strings.
         * @param inputVar - Input Array or String, Number, etc.
         * @return true if it is undefined/null/empty, false if it contains value(s)
         * Array or String containing just whitespaces or >'< or >"< or >[< or >]< is considered empty
         */
        /*
        function GlobalisLikeEmpty(inputVar) {
            if (typeof inputVar !== 'undefined' && inputVar !== null) {
                let strTemp = JSON.stringify(inputVar);
                strTemp = strTemp.replace(/\s+/g, ''); // remove all whitespaces
                strTemp = strTemp.replace(/\"+/g, "");  // remove all >"<
                strTemp = strTemp.replace(/\'+/g, "");  // remove all >'<
                strTemp = strTemp.replace(/[+/g, "");  // remove all >[<
                strTemp = strTemp.replace(/]+/g, "");  // remove all >]<
                if (strTemp !== '') {
                    return false;
                } else {
                    return true;
                }
            } else {
                return true;
            }
        }
        */
        
        AlCalzoneA Offline
        AlCalzoneA Offline
        AlCalzone
        Developer
        schrieb am zuletzt editiert von
        #23

        @christoph1337 sagte in [Vorlage] Hilfreiche JavaScript-Funktionen:

        Das Script geht garnicht bis Zeile 256...

        Hast du globale Skripte?

        Warum `sudo` böse ist: https://forum.iobroker.net/post/17109

        1 Antwort Letzte Antwort
        0

        Hey! Du scheinst an dieser Unterhaltung interessiert zu sein, hast aber noch kein Konto.

        Hast du es satt, bei jedem Besuch durch die gleichen Beiträge zu scrollen? Wenn du dich für ein Konto anmeldest, kommst du immer genau dorthin zurück, wo du zuvor warst, und kannst dich über neue Antworten benachrichtigen lassen (entweder per E-Mail oder Push-Benachrichtigung). Du kannst auch Lesezeichen speichern und Beiträge positiv bewerten, um anderen Community-Mitgliedern deine Wertschätzung zu zeigen.

        Mit deinem Input könnte dieser Beitrag noch besser werden 💗

        Registrieren Anmelden
        Antworten
        • In einem neuen Thema antworten
        Anmelden zum Antworten
        • Älteste zuerst
        • Neuste zuerst
        • Meiste Stimmen


        Support us

        ioBroker
        Community Adapters
        Donate

        391

        Online

        32.8k

        Benutzer

        82.9k

        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