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

  • Home
  • SEARCH
  • 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 6654509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:23:55+00:00 2026-05-26T01:23:55+00:00

I have some problems figuring out how to group to certain variables in javascript.

  • 0

I have some problems figuring out how to group to certain variables in javascript.

Here is the deal.

I have one array containing categories in my case right now categories A-Z but it could be anything (Animals – dogs – cats – etc).

In another array I have a result from an xml file with different content (title, content and category). In my case the category containing letters from A-Z corresponding to the category in my other array.

So what I want to do is first of all output one div for each category from the category array. When that is done I want to add inside each div the matching category items form my other array.

This is an example

First output from my category array:

<div id="A"></div>
<div id="B"></div>
<div id="C"></div>
<div id="D"></div>

Second I want to add inside those divs the array objects that has a matching category inside them A, B, C etc.

<div id="A">
<div id="contentFromMyOtherArray"> this object comes from my other array and had the content category A </div>
<div id="contentFromMyOtherArray"> this object also comes from my other array and had the content category A still inside the A div </div>
</div>
<div id="B">
<div id="contentFromMyOtherArray"> this object comes from the array and had the content category B </div>
</div>

And so on…

Is this even possible?

EDIT:
My First array only holds A, B, C, D, E etc so when iterating thru it array[i] i will get A B C D etc

My second array holds title category etc so if i want to have only the category i could iterate thru it like this arrMarkers[i].category. That would output ex. A A A B B E E F F F etc based on what categories the content of each array holds

  • 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-05-26T01:23:56+00:00Added an answer on May 26, 2026 at 1:23 am

    Assuming you have your arrays defined something like this:

    var categories = ['A', 'B', 'C', 'D'];
    var other = [];
    other['A'] = ['item 1', 'item 2', 'item 3'];
    other['B'] = ['item 4', 'item 5'];
    other['C'] = ['item 6'];
    

    Then try the following jQuery code to create the divs:

    $(document).ready(function() {    
        $.each(categories, function(index, category) {
            var categoryId = category.replace(/ /gi, '_');
            var newCategory = $('<div />').attr('id', categoryId);
            // you can set any other properties on this new div here using .attr()
            $.each(other[category], function(index, item) {
                var itemId = category + '_' + item.replace(/ /gi, '_');
                var newInnerDiv = $('<div />').attr('id', itemId);
                // set any other properties like text content, etc here
                newInnerDiv.appendTo(newCategory);
            });
            newCategory.appendTo('body');
        });
    });
    

    You can see a working example here: http://jsfiddle.net/greglockwood/8F8hv/

    Let me know if you have any problems.

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

Sidebar

Related Questions

I work with my student group on a project : We have some problems
We have some performance problems with one of our applications. I thought about using
I had some problems figuring out a good title, but hopefully the code examples
I have some problems with this code? Here is my code that creates text
I have some problems with Miktex installed on Windows Vista Business SP1/32 bit. I
I have some problems on a site with the concurrent access to a list.
I have some problems sending mails through SMTP using Spring's MailSender interface and the
I am very new to C and I have some problems learning about pointers.
Begining with JSP and servlet development, I have some problems with a bodyless custom
We have a couple of sites which have some memory problems and fairly often

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.