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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:35:25+00:00 2026-05-26T02:35:25+00:00

I created a nested array as I could so far but I feel like

  • 0

I created a nested array as I could so far but I feel like i did it wrong or something does not make sense. Could anyone please have a look and tell me if my array is the way to build nested array. All I want is to create rows under specific title, so I nested data and calling it with nested loops. Maybe theres is a simpler way of achiving it. Here is the code:

var data = [

    {title:'Row Title 1'},

    [{leftCol:'Some text for left column',rightCol:'Some text for right column'},
    {leftCol:'Some text for left column',rightCol:'Some text for right column'},
    {leftCol:'Some text for left column',rightCol:'Some text for right column'}],

    {title:'Row Title 2'},

    [{leftCol:'Some text for left column',rightCol:'Some text for right column'},
    {leftCol:'Some text for left column',rightCol:'Some text for right column'},
    {leftCol:'Some text for left column',rightCol:'Some text for right column'}]

    ];

    for (var i=0, j=data.length; i < j; i++) {

        if(data[i].title != null){
            document.write('<b>'+data[i].title+'</b><br />');
        }

        for(p=0,plen=data[i].length; p<plen;p++){
            document.write('<p style="background:#eee;">'+data[i][p].leftCol+'</p>');
            document.write('<p>'+data[i][p].rightCol+'</p>');       
        }
    }
  • 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-26T02:35:26+00:00Added an answer on May 26, 2026 at 2:35 am

    The structure you’re using should be more like this:

    var data = [
    
        {title:'Row Title 1', contents: [
    
          {leftCol:'Some text for left column',rightCol:'Some text for right column'},
          {leftCol:'Some text for left column',rightCol:'Some text for right column'},
          {leftCol:'Some text for left column',rightCol:'Some text for right column'}
    
        ],
    
        // ...
    ];
    

    That way, each row is an object with a “title” attribute and a “contents” attribute. Your loop would then look like this:

    for (var i=0, j=data.length; i < j; i++) {
    
        if(data[i].title != null){
            document.write('<b>'+data[i].title+'</b><br />');
        }
    
        for(var p=0, plen=data[i].contents.length; p < plen; p++){
            document.write('<p style="background:#eee;">'+data[i].contents[p].leftCol+'</p>');
            document.write('<p>'+data[i].contents[p].rightCol+'</p>');       
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to created nested dictionary variable like the below, But I get
because obj, the playingCard object is created inside a nested for loop does that
I would like to do something a bit tricky and I'm not sure the
I have created a nested list with drag/drop functionality. My issue is that I
I have javascript object which consists of complex array of structures with nested structures
I do not really understand how nested attributes work in Rails. I have 2
I'm not sure if this is possible in Spring MVC 3.0, but I'm trying
I want to transform the 'values' array created by xml_parse_into_struct() into a bunch of
my array jokesarray has elements like the following. I am trying to sort by
I am trying to create nested array's dynamically from a string that has been

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.