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 873725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:59:12+00:00 2026-05-15T10:59:12+00:00

My question is related to this question. You will have to first read it.

  • 0

My question is related to this question. You will have to first read it.

var ids = "1*2*3";
var Name ="John*Brain*Andy";
var Code ="A12*B22*B22";

Now that I have an array of javascript objects. I want to group my objects based on CODE. So there can be duplicate codes in that code string.

As per the above changed strings, I have same code for Brain and Andy. So, now I want two arrays. In one there will be only one object containing details of only John and in the other object there will be two objects containing details of Brain and Andy.

Just for example I’ve taken 3 items. In actual there can be many and also there can be many set of distinct codes.

UPDATE
I needed the structure like the one built in groupMap object by the @Pointy. But I will use @patrick’s code to achieve that structure. Many thanks to both of them.

  • 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-15T10:59:13+00:00Added an answer on May 15, 2026 at 10:59 am

    It is a little hard to tell the exact resulting structure that you want.

    This code:

           // Split values into arrays
    Code = Code.split('*');
    Name = Name.split('*');
    ids = ids.split('*');
    
           // cache the length of one and create the result object
    var length = Code.length;
    var result = {};
    
           // Iterate over each array item
           // If we come across a new code, 
           //    add it to result with an empty array
    for(var i = 0; i < length; i++) {
        if(Code[i] in result == false) {
            result[ Code[i] ] = [];
        }
                // Push a new object into the Code at "i" with the Name and ID at "i"
        result[ Code[i] ].push({ name:Name[i], id:ids[i] });
    }
    

    Will produce this structure:

    // Resulting object
    {
          // A12 has array with one object
        A12: [ {id: "1", name: "John"} ],
    
          // B22 has array with two objects
        B22: [ {id: "2", name: "Brain"},
               {id: "3", name: "Andy"}
             ]
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Another question related to this one . I have a List<SortableObjects> that is the
I have a question related to this one . I don't want to do
I have a question related to this one : I'm trying to attach an
This question is only related to the first parameter in any event handler, that
This question is related to others I have asked on here, mainly regarding sorting
I have question quite much related to this one I asked a while ago
This question is related to the numerical recipes in C++ book, so it will
Haven't seen many Geneva related questions yet, I have posted this question in the
I found this related question: How do I use composition with inheritance? I would
Please note this question related to performance only. Lets skip design guidelines, philosophy, compatibility,

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.