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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:01:06+00:00 2026-05-27T09:01:06+00:00

I have json data I’ve taken the first set of data and written it

  • 0

I have json data
I’ve taken the first set of data and written it to one ul.
I want to split the remaining data into 2 equal chunks and write to two other uls.

How do I split the remaining json after the initial index == 0?

my js code:

$("#storeList").append('<ul class="storeListLeft"></ul>');
    $("#storeList").append('<ul class="storeListRight"></ul>');

    //run store json data and append to storeList div
                                var object;
                                $.getJSON('xml/storeList.json', function(json) {
                                    object = json;
                                    $.each(object.storeList.state, function(index, value) {
                                    var list;
                                        if(index == 0) {
                                          list = $('.storeListLeft');
                                        } else {
                                          list = $('.storeListRight');
                                        }

                                            listItem = $('<li/>'),
                                            html = listItem.append($('<h3/>').text(this.stateName));

                                        $.each(this.store, function() {
                                            listItem.append($('<a />').attr('href', this.storeURL).attr('class', 'storeInactive').attr('id', this.storeID).text(this.storeName));
                                        });

                                        list.append(html)

                                    });
                                }); //end json render

CUrrent output:

<ul class="storeListLeft">
   <li>
       <h3>state Name</h3>
       <a>store Name</a>
   </li>
</ul>
<ul class="storeListRight">
   <li>
       <h3>state Name</h3>
       <a>store Name</a>
       <a>store Name</a>
       <a>store Name</a>
   </li>
    <li>
       <h3>state Name</h3>
       <a>store Name</a>
   </li>
</ul>

my desired output is to still assign the first item to the storeListLeft, and then split the remaining data and assign the chunks to 2 separate uls

so something like this:

<ul class="storeList_1"> //which is index == 0
   <li>
       <h3>state Name</h3>
       <a>store Name</a>
   </li>
</ul>
<ul class="storeList_2"> //2 & 3 are the split of the remainder after index == 0 
   <li>
       <h3>state Name</h3>
       <a>store Name</a>
       <a>store Name</a>
       <a>store Name</a>
   </li>
    <li>
       <h3>state Name</h3>
       <a>store Name</a>
   </li>
</ul>
<ul class="storeList_3">
   <li>
       <h3>state Name</h3>
       <a>store Name</a>
       <a>store Name</a>
       <a>store Name</a>
   </li>
    <li>
       <h3>state Name</h3>
       <a>store Name</a>
   </li>
</ul>
  • 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-27T09:01:07+00:00Added an answer on May 27, 2026 at 9:01 am

    Before the first loop break the states into the objects you want:

    //get the first state element in the array
    var firstStateArray = object.storeList.state.slice(0, 1);
    
    //get the half way point of the states
    var mid = Math.round((object.storeList.state.length - 1) / 2);
    
    //assign the first half of the array, starting at the second item (1) to the middle (mid)
    var secondStateArray = object.storeList.state.slice(1, mid);
    
    //assign the second half of the array but starting after the first half
    var thirdStateArray = object.storeList.state.slice(mid + 1);
    

    Here is a function to generate the markup:

    function GenerateMarkup(states, className) {
        var html = "<ul class='" + className + "'>";
    
        $.each(states, function () {
    
            html += "<li>";
    
            html += "<h3>" + this.stateName + "</h3>";
    
            $.each(this.store, function (index, value) {
                html += "<a href='" + this.storeURL + "' class='storeInactive' id='" + this.storeID + "'>" + this.storeName + "</a>";
            });
    
            html += "</li>";
    
        });
    
        html += "</ul>";
    
        $("#storeList").append(html);
    }
    

    And calling the function:

    //create first list...only one state
    GenerateMarkup(firstStateArray, "storeList_1");
    
    //create second list
    GenerateMarkup(secondStateArray, "storeList_2");
    
    //create third list
    GenerateMarkup(thirdStateArray, "storeList_3");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have some json data, and i want to convert it into plain text,
I have a JSON data like this: { hello: { first:firstvalue, second:secondvalue }, hello2:
I have following json data which I want to pass it to server using
i have this json data and i want to get length of this json
I have a JSON data object and a text/html javascript template written using the
I have JSON response from Facebook, which I don't want to deserialize into a
I have JSON data which come from server. I want to display organization chart
I have JSON data like this: [{id:3,name:jason},{id:4,name:karen}] I want to build a table view
I have some json data [{a:10, b:123,c:4.5},{a:2,b:5,c:33}] and so on that I read into
I have this json data: [ {ID:1,name:google,IP:69.5.33.22,active:true}, {ID:2,name:bing,IP:70.5.232.33,active:false} ] I want to get the

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.