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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:35:38+00:00 2026-06-06T14:35:38+00:00

Sorry if this has been asked before, but I couldn’t find a good example

  • 0

Sorry if this has been asked before, but I couldn’t find a good example of what I’m trying to accomplish. Maybe I’m just not searching for the right thing. Please correct me if there’s an explanation of this somewhere. Anyway…

I have JSON data structured like so…

{"Result":[
    {"Level":"ML","TeamName":"Team 1","League":"League 1"},
    {"Level":"ML","TeamName":"Team 2","League":"League 2"},
    {"Level":"ML","TeamName":"Team 3","League":"League 3"},
    {"Level":"3A","TeamName":"Team 4","League":"League 1"},
    {"Level":"3A","TeamName":"Team 5","League":"League 2"},
    {"Level":"3A","TeamName":"Team 6","League":"League 3"},
    {"Level":"2A","TeamName":"Team 7","League":"League 1"},
    {"Level":"2A","TeamName":"Team 8","League":"League 2"},
    {"Level":"2A","TeamName":"Team 9","League":"League 3"},
]}

I would like to group, or restructure it like so…

{"Result":[
    {"ML":[
        {"TeamName":"Team 1","League":"League 1"},
        {"TeamName":"Team 2","League":"League 2"},
        {"TeamName":"Team 3","League":"League 3"}
    ]},
    {"3A":[
        {"TeamName":"Team 4","League":"League 1"},
        {"TeamName":"Team 5","League":"League 2"},
        {"TeamName":"Team 6","League":"League 3"}
    ]},
    {"2A":[
        {"TeamName":"Team 7","League":"League 1"},
        {"TeamName":"Team 8","League":"League 2"},
        {"TeamName":"Team 9","League":"League 3"}
    ]}
]}

How would I accomplish this with Javascript/jQuery? Unfortunately I can’t edit what the server is sending me.

  • 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-06T14:35:39+00:00Added an answer on June 6, 2026 at 2:35 pm

    Just keep track of it all in an object:

    let groups = Object.create(null);
    
    data.forEach(item => {
        if (!groups[item.Level]) {
            groups[item.Level] = [];
        }
    
        groups[item.Level].push({
            TeamName: item.TeamName,
            League: item.League
        });
    });
    
    let result =
        Object.entries(groups)
            .map(([k, v]) => ({[k]: v}));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry if this has been asked before, I did check but couldn't find anything...
I'm sorry if this questions has been asked before, but I couldn't find an
Sorry if this has been asked before, but I couldn't find a solution to
Sorry if this has been asked before, I searched but couldn't find anything. I'm
I'm sorry if this has been asked before - but I couldn't find a
I'm sorry if this question has been asked already, but I couldn't find it
Sorry if this has been asked before but I've tried searching and can't find
Sorry if this has been asked before. I couldn't find a definitive answer. Can
Sorry if this has been asked before, but I can't find a clear enough
Sorry if this has been asked before, but I was unable to find it.

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.