Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7792345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:09:18+00:00 2026-06-01T22:09:18+00:00

pretty simple question, can’t quite fig. it out. I have 2 js array’s that

  • 0

pretty simple question, can’t quite fig. it out.

I have 2 js array’s that I need to combine into a new array, based on sub_key.

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"
       }
   ];

I’d like to create an array like so, which just combines the above 2, based on sub_key

var data = [
    COMMAND B=["foo"],
    95TH PCT=["bar","baz","buzz"]
    dummy4=[]
    ];

Here’s what I tried but it doesn’t work… i think i’m close?? thanks for any help!

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)
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T22:09:19+00:00Added an answer on June 1, 2026 at 10:09 pm

    Cleaning up your script, here is what you are trying to do. It craetes an array of objects using the Name from items and matching sub_key from sub_items.

    var items = [
      { OBJECTID: 1, 
        Name: 'COMMAND B', 
        ID: 'AR0xx', 
        sub_key: '1000' 
      }, 
      { OBJECTID: 2, 
        Name: '95TH PCT', 
        ID: 'AR0xx', 
        sub_key: '1001' 
      }, 
      { OBJECTID: 379, 
        Name: 'dummy4', 
        ID: 'AR0xx', 
        sub_key: '9999' 
      } 
    ]; 
    
    var subitems = [ 
      { BJECTID: 787,
        ID: 'AR0xx', 
        sub_key: '1000', 
        Long_Name: 'foo' 
      }, 
      { OBJECTID: '789', 
        ID: 'AR0xx', 
        sub_key: '1001', 
        Long_Name: 'bar' 
      }, 
      { OBJECTID: '1', 
        ID: 'AR0xx', 
        sub_key: 1001, 
        Long_Name: 'baz' 
      }, 
      { OBJECTID: '788', 
        ID: 'AR0xx', 
        sub_key: '1001', 
        Long_Name: 'buzzz' 
      } 
    ]; 
    
    var j = subitems.length;
    var result = {};
    var p;
    var sub_key;
    var obj;
    
    for (var i=0, iLen = items.length; i<iLen; i++) {
      p = items[i].Name;
      result[p] = [];
      sub_key = items[i].sub_key;
    
      for (var j=0, jLen=subitems.length; j<jLen; j++) {
    
        if (subitems[j].sub_key == sub_key) {
          result[p].push(subitems[j].Long_Name);
        }
      }
    }
    
    alert(result['95TH PCT']); // bar, baz, buzz
    

    Edit

    Return a single object rather than an array of objects, which I think is what is required.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Pretty simple question that I can't quite find the answer for: Is there a
I have a pretty simple Rails question regarding encoding that I can't find an
Pretty simple question. I have a few ASP RequiredFieldValdators checking some text boxes. Out
I have a pretty simple question: how can I terminate a running script in
Pretty simple question, I have a webpage that is used exclusively on iPads. I've
Pretty simple question, but I can't seem to figure out how to do this,
Pretty simple question, how can I transform a number (1, 2, 3, etc) into
I have a pretty simple question, but with an answer that I am unable
I know this is a pretty simple question but I can't figure out where
I have a pretty simple game that is out on the Market right now.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.