MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    How to declare an array in config.js?

    Scheduled Pinned Locked Moved Troubleshooting
    6 Posts 3 Posters 1.1k Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • F Offline
      fischershaw
      last edited by

      How does one declare an array in config.js within the config object? Just using [] does not work. For instance, declaring the following within a module’s config object:

      biff: ['muffy','sport','spam']
      

      does NOT create an array. Instead, what is created is the comma separated string: “muffy,sport,spam”.

      bheplerB 1 Reply Last reply Reply Quote 0
      • bheplerB Offline
        bhepler Module Developer @fischershaw
        last edited by

        @fischershaw - Try double quotes. The " character.

        biff: ["muffy","sport","spam"],
        

        Don’t forget the trailing comma.

        F 1 Reply Last reply Reply Quote 0
        • F Offline
          fischershaw @bhepler
          last edited by

          @bhepler Yes, the trailing comma is present. The config.js file is syntactically correct, it just produces unexpected results. In this case a string instead of an array.

          S 1 Reply Last reply Reply Quote 0
          • S Offline
            sdetweil @fischershaw
            last edited by sdetweil

            @fischershaw @bhepler the way you have done it works for me…

            from my MyCovid19 module
            in config.js

            			config:{
            				countries:["Italy","USA","China","Spain", "France",'Sweden'],
            

            in my code

             for(var i in this.config.countries){
                    switch(this.config.countries[i].toLowerCase()) {
            

            oh, single or double quotes doesn’t matter, even in the same array, long as they are matched

            why do you think it is a string? its an array of strings

            • open the developers window, (npm start dev or ctrl-shift-i on the keyboard),

            • select the sources tab,

            • look thru the items on the left, expand modules, find your module, click its .js file ,

            • then put a stop (click on the line edge to the left of the 1st statement after start),

            • then hit f5 (refresh page) and the page will be reloaded and the debugger will stop on that statement,

            • u can examine the variables in the config object

            Sam

            How to add modules

            learning how to use browser developers window for css changes

            F 1 Reply Last reply Reply Quote 1
            • F Offline
              fischershaw @sdetweil
              last edited by

              @sdetweil My dumb error which I corrected. Sorry to bother you.

              S 1 Reply Last reply Reply Quote 0
              • S Offline
                sdetweil @fischershaw
                last edited by

                @fischershaw is ok, we all learn… I just spent 2 hours trying to figure out why an api request failed, 404 not found

                I had spelled apikey with an uppercase K…

                which debugging approach did you use?

                Sam

                How to add modules

                learning how to use browser developers window for css changes

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post
                Enjoying MagicMirror? Please consider a donation!
                MagicMirror created by Michael Teeuw.
                Forum managed by Sam, technical setup by Karsten.
                This forum is using NodeBB as its core | Contributors
                Contact | Privacy Policy