title: Javascript Data Structure - bootstrap treeview nodes
body: <p>I have a question about data structure. I want to create a array by using for loop or for each with javascript, but I have no idea how to make it.</p>
  <p>If you have any idea about it like for-loop with example, please help me.</p>
  <p>Here is its code. I want to make from dataArr to tree Structure by using some logic.</p>
  <p>Thanks in advance.</p>
  <p>====================== Input ==========================</p>
  <pre><code>    var dataArr =
                  [
                       {&quot;LG&quot;: &quot;A&quot;, &quot;MD&quot;: &quot;A1&quot;, &quot;SM&quot;: &quot;A1a&quot;},
                       {&quot;LG&quot;: &quot;A&quot;, &quot;MD&quot;: &quot;A1&quot;, &quot;SM&quot;: &quot;A1b&quot;},
                       {&quot;LG&quot;: &quot;A&quot;, &quot;MD&quot;: &quot;A1&quot;, &quot;SM&quot;: &quot;A1c&quot;},
                       {&quot;LG&quot;: &quot;A&quot;, &quot;MD&quot;: &quot;A2&quot;, &quot;SM&quot;: &quot;A2a&quot;},
                       {&quot;LG&quot;: &quot;A&quot;, &quot;MD&quot;: &quot;A2&quot;, &quot;SM&quot;: &quot;A2b&quot;},
                       {&quot;LG&quot;: &quot;A&quot;, &quot;MD&quot;: &quot;A2&quot;, &quot;SM&quot;: &quot;A2c&quot;},
                       {&quot;LG&quot;: &quot;B&quot;, &quot;MD&quot;: &quot;B1&quot;, &quot;SM&quot;: &quot;B1a&quot;},
                       {&quot;LG&quot;: &quot;B&quot;, &quot;MD&quot;: &quot;B1&quot;, &quot;SM&quot;: &quot;B1b&quot;},
                       {&quot;LG&quot;: &quot;B&quot;, &quot;MD&quot;: &quot;B1&quot;, &quot;SM&quot;: &quot;B1c&quot;},
                       {&quot;LG&quot;: &quot;C&quot;, &quot;MD&quot;: &quot;C1&quot;, &quot;SM&quot;: &quot;C1a&quot;},
                       {&quot;LG&quot;: &quot;C&quot;, &quot;MD&quot;: &quot;C1&quot;, &quot;SM&quot;: &quot;C1b&quot;},
                       {&quot;LG&quot;: &quot;C&quot;, &quot;MD&quot;: &quot;C1&quot;, &quot;SM&quot;: &quot;C1c&quot;}
                   ]
  </code></pre>
  <p>====================== Output ==========================</p>
  <pre><code>    var tree = [
                  {
                    text: &quot;A&quot;,
                    nodes: [
                      {
                        text: &quot;A1&quot;
                        ,nodes: [
                          {
                            text: &quot;A1a&quot;
                          },
                          {
                            text: &quot;A1b&quot;
                          },
                          {
                            text: &quot;A1c&quot;
                          }
                         ]
                      },
                      {
                            text: &quot;A2&quot;
                            ,nodes: [
                              {
                                text: &quot;A2a&quot;
                              },
                              {
                                text: &quot;A2b&quot;
                              },
                              {
                                text: &quot;A2c&quot;
                              }
                             ]
                      }
                    ]
                   },
                   {
                    text: &quot;B&quot;,
                    nodes: [
                      {
                        text: &quot;B1&quot;
                        ,nodes: [
                          {
                            text: &quot;B1a&quot;
                          },
                          {
                              text: &quot;B1b&quot;
                          },
                          {
                              text: &quot;B1c&quot;
                          }
                        ]
                      }
                    ]
                   },
                   {
                       text: &quot;C&quot;,
                       nodes: [
                               {
                                   text: &quot;C1&quot;
                                       ,nodes: [
                                                {
                                                    text: &quot;C1a&quot;
                                                },
                                                {
                                                    text: &quot;C1b&quot;
                                                },
                                                {
                                                    text: &quot;C1c&quot;
                                                }
                                                ]
                               }
                               ]
                   }
                  ]
  </code></pre>