combine js array's
<p>pretty simple question, can't quite fig. it out. </p>

<p>I have 2 js array's that I need to combine into a new array, based on sub_key.</p>

<pre><code>var items = [
    Object { 
        OBJECTID=1,
        Name="COMMAND B", 
        ID="AR0xx",
        sub_key="1000"
        },
    Object {
        OBJECTID=2, 
        Name="95TH PCT", 
        ID="AR0xx",
        sub_key="1001"
        },
   Object { 
        OBJECTID=379, 
        Name="dummy4", 
        ID="AR0xx",
        sub_key="9999"
        }
   ];

var subitems = [
   Object { 
       OBJECTID=787, 
       ID="AR0xx", 
       sub_key=1000, 
       Long_Name = foo
       }, 
   Object { 
       OBJECTID=789, 
       ID="AR0xx", 
       sub_key=1001, 
       Long_Name = "bar"
       }, 
   Object { 
       OBJECTID=1, 
       ID="AR0xx", 
       sub_key=1001, 
       Long_Name="baz"
       }, 
   Object { 
       OBJECTID=788,
       ID="AR0xx", 
       sub_key=1001,
       Long_Name="buzzz"
       }
   ];
</code></pre>

<p>I'd like to create an array like so, which just combines the above 2, based on sub_key</p>

<pre><code>var data = [
    COMMAND B=["foo"],
    95TH PCT=["bar","baz","buzz"]
    dummy4=[]
    ];
</code></pre>

<p>Here's what I tried but it doesn't work... i think i'm close?? thanks for any help!</p>

<pre><code>data = [];
for (var key in items){
    var o = items[key];
    //data.push(o.Name);
    for (var subkey in subitems){
        subo = subitems[subkey];
        if (o.sub_key == subo.sub_key){
            data[o.Name].push(subo.Long_Name)
        }
    }
}
</code></pre>
