MagicMirror² v2.12.0 is available! For more information about this release, check out this topic.

How to declare an array in config.js?



  • 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”.


  • Project Sponsor

    @fischershaw - Try double quotes. The " character.

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

    Don’t forget the trailing comma.



  • @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.



  • @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



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



  • @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?


Log in to reply