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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:27:25+00:00 2026-06-18T00:27:25+00:00

I have the following array format: var myArr = [ { a: 1, b:

  • 0

I have the following array format:

var myArr = [
{
    "a": "1",
    "b": "2",
    "c": "3",
    "d" {
        "0" : "1",
        "1" : "2"
    },
    "blah" : "me"
},
{
    "a": "5",
    "b": "3",
    "c": "1",
    "d" {
        "0" : "6",
        "1" : "3"
    },
    "blah" : "me"
},
{
    "a": "5",
    "b": "3",
    "c": "1",
    "d" {
        "0" : "6",
        "1" : "3"
    },
    "blah" : "you"
}
]

I am wondering how I could map a new array such that the values under “blah” are together like

var myArr = [{
    "me" : [
    {
        "a": "1",
        "b": "2",
        "c": "3",
        "d": {
            "0" : "1",
            "1" : "2"
            }
    },
    {
        "a": "5",
        "b": "3",
        "c": "1",
        "d": {
            "0" : "6",
            "1" : "3"
            }
    }
    ],
    "you" : [
    {
        "a": "5",
        "b": "3",
        "c": "1",
        "d": {
            "0" : "6",
            "1" : "3"
            }
    }
    ]
}]
  • 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-18T00:27:26+00:00Added an answer on June 18, 2026 at 12:27 am

    That’s very possible, try this:

    var output = {};
    myArr.forEach(function(elem){     // Loop trough the elements in `myArr`
        if(!output[elem.blah]){       // If the output object doesn't have a property named by elem.blah, yet
            output[elem.blah] = [];   // Create a empty array
        }
        output[elem.blah].push(elem); // Push the current element to that array
        delete elem.blah;             // And delete the mention of `blah` from it (optional)
    });
    

    Instead of forEach, you can also use a normal for loop, for more compatibility:

    var output = {};
    for(var i = 0; i < myArr.length; i++){ // Loop trough the elements in `myArr`
        var elem = myArr[i];
        if(!output[elem.blah]){            // If the output object doesn't have a property named by elem.blah, yet
            output[elem.blah] = [];        // Create a empty array
        }
        output[elem.blah].push(elem);      // Push the current element to that array
        delete elem.blah;                  // And delete the mention of `blah` from it (optional)
    });
    

    With underscore.js, you can just do this:

    _.groupBy(myArr, 'blah');
    

    the only difference is that this won’t remove the blah property from the source objects.

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

Sidebar

Related Questions

I have an array in the following format: var markers = [ ['Title', 15.102253,
I have following array, that I need to operate by hand on bitmaps. const
I have a page that I want to scrape that has the following format:
All, I have the following array in array format. The JSON format is shown
I have following array that contains information on each file.but it is in single
I have the following array final byte[] texttoprint = new byte[]{0x1b, 0x40, 0x1b,0x74,0x0D, (byte)
I have a large array in this format: var cars = [{brand:Honda,year:2002},{brand:Toyota,year:2000},{brand:Subaru,year:2009}]; The array
I have been given an array in the following format and need to put
Hi there I was wondering if somebody could help me? I have the following
So I have a problem with the following code. I have an array that

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.