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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:13:09+00:00 2026-05-26T08:13:09+00:00

I have the following JSON Object being loaded into my application and stored into

  • 0

I have the following JSON Object being loaded into my application and stored into a var called obj:

{
    "items" : [
    {
        "name" : "item-1",
        "group" : [
        {
            "groupName" : "name-1",
            "groupPosition" : 2
        },
        {
            "groupName" : "name-2",
            "groupPosition" : 1
        }]
    },
    {
        "name" : "item-2",
        "group" : [
        {
            "groupName" : "name-1",
            "groupPosition" : 1
        },
        {
            "groupName" : "name-2",
            "groupPosition" : 2
        }]
    }]
}

I then do the following to go through it:

var groups = new Array();
var items = new Array();
$.each(obj.items, function(i,r){
    var itemName = r.name;
    $.each(r.group, function(index, record){
        if ($.inArray(record.groupName) == -1) {
            groups.push(record.groupName);
            $('body').append('<div id="record.groupName"></div>');
        }
        $('#'+record.groupName).append('<div id="itemName">itemName</div>');
        // At this point I'm stuck as the items get added in order of iteration,
        // not according to their record.groupPosition value.
    });
});

There will eventually be several hundred “items” each contained within an unset number of “groups”.

The trouble I’m having is how to iterate through the JSON object using jQuery or good ol’JavaScript and display the items in the correct position within each group as the items and groups won’t be listed inside the JSON object in sequential order.

Any help would be greatly appreciated!

Thank you.

  • 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-26T08:13:09+00:00Added an answer on May 26, 2026 at 8:13 am

    Why not just give the group items the position index like this:

    {
    "items" : [
    {
        "name" : "item-1",
        "group" : {
        2:{
            "groupName" : "name-1",
            "groupPosition" : 2
        },
        1:{
            "groupName" : "name-2",
            "groupPosition" : 1
        }}
    
    },
    {
        "name" : "item-2",
        "group" : {
        1:{
            "groupName" : "name-1",
            "groupPosition" : 1
        },
        2:{
            "groupName" : "name-2",
            "groupPosition" : 2
        }}
    }]
    

    }

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

Sidebar

Related Questions

I have the following JSON object as a String: [{Add1:101,Description:null,ID:1,Name:Bundesverfassung,Short:BV},{Add1:220,Description:null,ID:2,Name:Obligationenrecht,Short:OR},{Add1:210,Description:null,ID:3,Name:Schweizerisches Zivilgesetzbuch,Short:ZGB},{Add1:311_0,Description:null,ID:4,Name:Schweizerisches Strafgesetzbuch,Short:null}] Now i
I have the following JSON object being returned from my webserver. I can't figure
I have the following JSON object: { response: { status: 200 }, messages: [
say I have the following json object; {'fname':'john', 'lname':'Locke'} and the following text boxes
I have an json output of the following (ignore the escape characters) {\sEcho\:1,\iTotalRecords\:10,\iTotalDisplayRecords\:10,\aaData\:[{\Job\:\developer\,\Name\:\kurt\},{\Job\:\plumber\,\Name\:\john\}]} which
I have follwing JSON: {mykey:[{name:Jak,interests:movies}]} and following opensocial app code: <script type=text/os-template require=mykey> <ul>
I have the following json object i need to alert it through javascript. {data:[{empmenuid:1,empid:null,deptid:66,aliasid:66,firstname:66,lastname:66,sin:66,status:66,empclass:66,hiredate:66,seneoritydate:66,separationdate:66,recalldate:66,martialstatus:66,gender:66,ethinicorigin:66,ethinicsuborigin:66,nationality:66,address1:66,address2:66,city:66,province:66,postalcode:66,country:66,email:66,officialemail:66,phone:66,otherphone:66,fax:66,officephone:66,officeext:66,officefax:66,mobilephone:66,pager:66,locid:66,jobtitle:66,jobtitlestart:66,fullpart:66,manager:66,managername:66,middlename:66,nickname:66,paytype:66,payfreq:66},{empmenuid:3,empid:null,deptid:12,aliasid:12,firstname:12,lastname:12,sin:12,status:12,empclass:12,hiredate:12,seneoritydate:12,separationdate:12,recalldate:12,martialstatus:12,gender:12,ethinicorigin:12,ethinicsuborigin:12,nationality:12,address1:12,address2:12,city:121,province:12,postalcode:12,country:12,email:12,officialemail:12,phone:12,otherphone:12,fax:12,officephone:12,officeext:12,officefax:12,mobilephone:12,pager:12,locid:12,jobtitle:12,jobtitlestart:12,fullpart:12,manager:12,managername:12,middlename:12,nickname:12,paytype:12,payfreq:12}],
Example: I have the following JSON object. {currentVersion : 10.0, folders : [], services
I need to parse json object for this url I have used following code
I have the following php object(??? new to this). It is being sent through

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.