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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:02:35+00:00 2026-05-28T17:02:35+00:00

Consider this Array var LIST =[]; LIST[‘C’]=[]; LIST[‘B’]=[]; LIST[‘C’][‘cc’]=[]; LIST[‘B’][‘bb’]=[]; LIST[‘C’][‘cc’].push(‘cc0’); LIST[‘C’][‘cc’].push(‘cc1’); LIST[‘C’][‘cc’].push(‘cc2’); LIST[‘B’][‘bb’].push(‘bb0’);

  • 0

Consider this Array

var LIST =[];

LIST['C']=[];
LIST['B']=[];

LIST['C']['cc']=[];
LIST['B']['bb']=[];  

LIST['C']['cc'].push('cc0');
LIST['C']['cc'].push('cc1');
LIST['C']['cc'].push('cc2');
LIST['B']['bb'].push('bb0');
LIST['B']['bb'].push('bb1');
LIST['B']['bb'].push('bb2');

I can loop through this array like

  for(var i in LIST){

      console.log(i)//C,B
      var level1=LIST[i];

      for(var j in level1){
        console.log(j)//cc,bb
        // etc...
      }

   }

Fine.. I have few basic questions.

1.How to sort the array in each level?

One level can be sort by .sort(fn) method . How can i pass to inner levels?

2.Why the indexOf method does not works to find the elements in first two levels?

If it’s because of the a non string parameter .. how can i search an array items in array if the item is not string?

3.How for(var i in LIST) works ?
I just need a basic understanding of indexing and looping through array ..

Thanks ..

  • 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-28T17:02:37+00:00Added an answer on May 28, 2026 at 5:02 pm

    LIST is NOT a three dimensional array in Javascript, it is just an array.

    //declare an array which names LIST.
    var LIST = [];
    
    //set a property named 'C' of the LIST to be an array.
    LIST['C']=[];
    //set a property named 'B' of the LIST to be an array.
    LIST['B']=[];
    
    //set a property named 'cc' of the 'LIST.C'(which is an array object)
    LIST['C']['cc']=[];
    //set a property named 'bb' of the 'LIST.B'(which is an array object)
    LIST['B']['bb']=[];  
    

    The fact is you only need to let the last level to be an array, see my example code below.

    function iterateOrderd(obj) {
        if (obj instanceof Array) {
            obj.sort();
            for (var j = 0, l=obj.length; j < l; j++) {
                console.log(obj[j]);
            }
        } else {
            var sortable = [];
            for (var i in obj) {
                if (obj.hasOwnProperty(i)) {
                    sortable.push(i);
                }
            }
            sortable.sort();
            for (var j = 0, l=sortable.length; j < l; j++) {
                console.log(sortable[j]);
                iterateOrderd(obj[sortable[j]]);
            }
        }
    }
    
    
    var LIST = {};
    
    LIST['C'] = {};
    LIST['B'] = {};
    
    LIST['C']['cc']=[];
    LIST['B']['bb']=[];  
    
    LIST['C']['cc'].push('cc0');
    LIST['C']['cc'].push('cc1');
    LIST['C']['cc'].push('cc2');
    LIST['B']['bb'].push('bb0');
    LIST['B']['bb'].push('bb1');
    LIST['B']['bb'].push('bb2');
    
    iterateOrderd(LIST);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider this array in PHP: $list = array('apple','orange','alpha','bib','son','green','odd','soap'); How can i get a sub
Consider this array. It has no keys, so I am not sure I can
Consider this small snippet of JavaScript: for(var i in map.maps) { buttons.push($(<button>).html(i).click(function() { alert(i);
Consider this array string[] presidents = { Adams, Arthur, Buchanan, Bush, Carter, Cleveland, Clinton,
Do you consider this a code smell? foreach((array)$foo as $bar) { $bar->doStuff(); } Should
I know the question sounds silly, but consider this: I have an array of
Consider a string array shaped like this: string[] someName = new string[] { First,
Consider this code: int size = 100 * 1000 * 1000; var emu =
Consider this Perl code my @a=[[1]]; print $a[0][0]; **output** ARRAY(0x229e8) Why does it print
get current array position pointer while doing foreach $object->result_array() Hi, consider this, a case.

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.