title: How to create dynamic dropdown from nested object
body: <p>How to bring the second selection drop down dynamically from the nested array objects. i am able to get the first drop down data but on select of the fist selection list i want to bring the list of processors.</p>
  
  <p>My Json data is as below. </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var cpumanufacturers = [
     {
         "name": "Intel",
         "values": [
           {
             "Intel Bulldozer Processors": [
               "Intel Bulldozer 1",
               "Intel Bulldozer 2",
               "Intel Bulldozer 3",
               "Intel Bulldozer 4",
               "Intel Bulldozer 5"
             ]
           },                          
           {
             "Intel Ryzen Processors": [
               "Intel Ryzen 1",
               "Intel Ryzen 2",
               "Intel Ryzen 3",
               "Intel Ryzen 4",
               "Intel Ryzen 5"
             ]
           }
         ]
       },
       {
         "name": "AMD",
         "values": [
           {
             "AMD Bulldozer Processors": [
               "AMD Bulldozer 1",
               "AMD Bulldozer 2",
               "AMD Bulldozer 3",
               "AMD Bulldozer 4",
               "AMD Bulldozer 5"
             ]
           },            
           {
             "AMD Ryzen Processors": [
               "AMD Ryzen 1",
               "AMD Ryzen 2",
               "AMD Ryzen 3",
               "AMD Ryzen 4",
               "AMD Ryzen 5"
             ]
           }
         ]
       }
     ];
  
  //And my code snippet is as below.
  
  for(var i = 0; i &lt; cpumanufacturers.length; i++) {   
     var cpumanufacturer = cpumanufacturers[i].values.map( k =&gt; Object.keys(k).shift());   
     var optgroup = $("&lt;optgroup&gt;").prop("label", cpumanufacturers[i].name);
     for(var model = 0; model &lt; cpumanufacturer.length; model++){    
      optgroup.append($("&lt;option&gt;").text(cpumanufacturer[model]));
     }   
     $("#processor").append(optgroup);   
    }
  
  $('#processor').on("change", function (e) {
   
   var selected = $(this).val();     
   var item = cpumanufacturers[0].values[selected];     
   jQuery("#pmodel").append($("&lt;option&gt;").text(cpumanufacturers[0].values[selected]));
      //secondSelect.empty().append("&lt;option value='' &gt;select&lt;/option&gt;").change();
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  
  &lt;label for="processor" class="pcspeclabel"&gt;*CPU Manufacturer&lt;/label&gt;&lt;br&gt;
   &lt;select id="processor" class="pcspecinput"&gt;
  
   &lt;/select&gt; 
   &lt;label for="pmodel" class="pcspeclabel"&gt;*CPU Model&lt;/label&gt;
   &lt;select id="pmodel" class="pcspecinput"&gt;&lt;/select&gt;
  
   </code></pre>
  </div>
  </div>
  </p>