Cannot read property 'concat' of undefined
<p>to begin with, I have a multilevel of entities as in</p>

<p><strong>country unit</strong> ----> <strong>customer reporting group</strong> ----> <strong>customers</strong></p>

<p>each <strong>country unit</strong>  has different <strong>customer reporting groups</strong> and each of the later has different <strong>customers</strong></p>

<p>in the code the variable names are</p>

<p>cu ----> crg ---> customer</p>

<p>this is represented in a multilevel object called menuData:</p>

<pre><code>menuData = {
    cu1: {
        CRG3: {
            Customer1: {},
            Customer5: {}
        },
        CRG7: {
            Customer3: {},
            Customer2: {},
            Customer7: {}
        }
    },
    cu4: {
        CRG1: {
            Customer2: {},
            Customer4: {}
        },
        CRG3: {
            Customer4: {}
        }
    }
};
</code></pre>

<p>what I wanted to do is to construct unique id for each level in a <strong>multilevel objects</strong> as well as in for example the ids for the customer units will be the same</p>

<p>cu1 and cu2 and so on</p>

<p>for the customer reporting groups the ids will consist of the cu + the crg as in
cu1+crg4</p>

<p>for the customer:</p>

<p>cu1+crg4+customer6;</p>

<p>what I did is a function called getIds</p>

<pre><code>var getIds = function(menuData) {
    var ids = {};
    for (cu in menuData) {
        ids[cu] = cu;
        for (crg in menuData[cu]) {
            if (!(ids[cu] in ids)) {
                ids[cu] = {};
                ids[cu][crg] = ids[cu].concat(crg);
            } else ids[cu][crg] = ids[cu].concat(crg);
            for (customer in menuData[cu][crg]) {
                if (!ids[cu][crg]) {
                    ids[cu][crg] = {};
                    ids[cu][crg][customer] = ids[cu][crg].concat(customer);
                } else ids[cu][crg][customer] = ids[cu][crg].concat(customer);
            }
        }
    }
    console.log(ids);
    return ids;
};
</code></pre>

<p>the error I got is</p>

<blockquote>
  <p>Cannot read property 'concat' of undefined</p>
</blockquote>

<p>what I have tried is that, because it says that it's undefined, I try to define it if its not already defined as in</p>

<pre><code>if (!(ids[cu] in ids)) {
    ids[cu] = {};
    ids[cu][crg] = ids[cu].concat(crg);
}
</code></pre>

<p>if its not defined, define it and insert the value, but if its defined, only assign the value
else ids[cu][crg] = ids[cu].concat (crg );</p>

<p>why do I get this error? and how to get the the ids in  multilevel objects ?</p>

<hr>

<p>edit, excpected output is </p>

<pre><code>ids = {
    "cu1": {
        "cu1+CRG3": { "cu1+CRG3+Customer1":{}, "cu1+CRG3+Customer5":{} },
        "cu1+CRG7": { "cu1+CRG7+Customer3":{}, "cu1+CRG7+Customer2":{}, "cu1+CRG7+Customer7":{} }
    },
    "cu4": {
        "cu4+CRG1": { "cu4+CRG1+Customer2":{}, "cu4+CRG1+Customer4":{} },
        "cu4+CRG3": { "cu4+CRG3+Customer4":{}}
    }
}
</code></pre>