title: Creating a JSON object from Javascript array
body: <p>So for each checkbox selected, I am getting the associated id and depending on values there deducing the node values, which is working fine. The problem I am facing is creating a proper javascript object with values from all checkboxes.</p>
  
  <p>Here's the function,</p>
  
  <pre><code>function finlizeJParams()
                      {
                          var jsonOutput=[];
                          var array =  $("input[type='checkbox']:checked").map(function(){ 
  
                              var str=this.id;
  
                              var data=[];
                              var objID=str.substring(str.lastIndexOf("c_")+2,str.lastIndexOf("_n_"));
                              var objName=str.substring(str.lastIndexOf("_n_")+3,str.lastIndexOf("_p_"));
                              var objParentID=str.substring(str.lastIndexOf("_p_")+3,str.lastIndexOf("_pn_"));
                              var objParentName=str.substring(str.lastIndexOf("_pn_")+4);
  
                              data['ItemID']=objID;
                              data['ItemName']=objName;
                              data['ItemParentID']=objParentID;
                              data['ItemParentName']=objParentName;
                              jsonOutput.push(data)
  
                              return jsonOutput;
                          }).get()
  
                          JSON.stringify(array);
                      }
  </code></pre>
  
  <p>This seems to be working as I am getting arrays when I try to print it on console, See below</p>
  
  <pre><code>0: Array[0]
      ItemParentName: "Fruit"
      ItemParentID: "7"
      ItemID: "8"
      ItemName: "Apple"
  1: Array[0]
      ItemParentName: "Fruit"
      ItemParentID: "7"
      ItemID: "9"
      ItemName: "Orange"
  </code></pre>
  
  <p>However, if I do a <em>JSON.stringify(jsonOutput)</em>, I get empty arrays [[],[]]? What am I doing wrong? Also, how can I group these array by parentID/Name and then convert to a JSON object?</p>