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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:37:15+00:00 2026-06-17T11:37:15+00:00

I have JSON document which has some nested arrays. And I want to make

  • 0

I have JSON document which has some nested arrays. And I want to make function AAA() which recalls every time if an array has nested array. And then stop when there isn’t more nested arrays.

For example. If I have:

         array[AAA,BBB,CCC]
                |
               AAA[AAA,BBB,CCC]
                    |
                   AAA[AAA,BBB,CCC]
                        |
                       etc.

I want to call function AAA() always when AAA has a subarray. Let’s say AAA has 5 times subAAA. I want the function(AAA) to call itself 5 times and then stop. And if in future I add more subarrays to call more times.

If it will help here is my .json:

{
    "navigation" : [

        {
            "name" : "home",
            "href" : "home.html"    
        },

        {
            "name" : "services",
            "href" : "interior.html",
            "navigation" : [
                {
                    "name" : "PROJECT MANAGEMENT",
                    "href" : "interior.html",
                    "navigation" : [
                            {
                                "name" : "PROJECT MANAGEMENT",
                                "href" : "interior.html"
                            },
                            {
                                "name" : "BUSINESS ANALYST",
                                "href" : "interior.html"
                            }
                        ]
                },
                {
                    "name" : "BUSINESS ANALYST",
                    "href" : "interior.html"
                }
            ]
        },

        {
            "name" : "company",
            "href" : "home.html"    
        }


    ]
}

And the js code is:

function parseJSON(){

        var navigation = new_json['navigation'];
        var nav_html = '';

        for (var i = 0; i < navigation.length; i++) {

            var name = navigation[i]['name'];
            var href = navigation[i]['href'];
            var submenu = navigation[i]['navigation'];

            nav_html += '<li><a href="' + href + '">' + name + '<span class="ddArrow"></span></a>';     

            if( typeof(submenu) != 'undefined' ){
                nav_html += '<ul>';

                for( var j=0; j<submenu.length; j++ ){

                    var submenu_name = submenu[j]['name'];
                    var submenu_href = submenu[j]['href'];

                    nav_html += '<li><a href="' + submenu_href + '">' + submenu_name + '</a></li>';         
                }
                nav_html += '</ul>';
            }
            nav_html += '</li>';
            console.log( nav_html );
            $('#navigation ul').html( nav_html );
        };  
    };

That way I want to create navigation which has submenus. Now I have 3 levels, but if I decide to add 4th and 5th. I want my code to parse them in the HTML without writing more code. I have the rest … I just need to the IF when function stops.

I simply don’t write what I have tried because I understand why is not working.

  • 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-17T11:37:16+00:00Added an answer on June 17, 2026 at 11:37 am

    A recursive function is quite simple to build, and is very similar to the code you already have:

    function parseJSON() {
        function makeList(navigation) {
            var nav_html = '';
            for (var i = 0; i < navigation.length; i++) {
                var name = navigation[i]['name'],
                    href = navigation[i]['href'],
                    submenu = navigation[i]['navigation'];
    
                nav_html += '<li><a href="' + href + '">' + name + '<span class="ddArrow"></span></a>';     
    
                if( typeof(submenu) != 'undefined' ){
                    nav_html += '<ul>';
                    // now here, do not iterate it again!
                    // call the function recursively!
                    nav_html += makeList(submenu);
                    nav_html += '</ul>';
                }
                nav_html += '</li>';
            }
            return nav_html;
        }
        $('#navigation ul').html( makeList( new_json['navigation'] ) );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JSON file which has 40k documents, each document contains a date
I have a JSON object items which has few items that I want to
I have updated my jSon object using the code <script type=text/javascript > jQuery(document).ready(function($){ var
I have the following simple jquery snippet $(document).ready(function () { $.ajax({ url:myjson.json, dataType: 'json',
I have JSON string that has nested objects with dynamic names that vary each
I have this JSON file I generate in the server I want to make
Hi every one, I have a login form which has mail id and password,
I'm implementing a service where each user must have his own json/document database. Beyond
I have Ajax file in which code has written to accept values form user
I have the following form (below) which has a hidden input tag. On form

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.