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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:31:19+00:00 2026-05-22T21:31:19+00:00

I need to create an array from tree elements in Javascript and being a

  • 0

I need to create an array from tree elements in Javascript and being a newbie I don’t know how to achieve this.

pseudo-code :

function make_array_of_tree_node(tree_node)
{
   for (var i = 0; i < tree_node.childCount; i ++) {
      var node = tree_node_node.getChild(i);
      if (node.type ==0) {
         // Here I'd like to put a link (node.title) in an array as an element
      } else if (node.type ==6) {
         // Here the element is a folder so a I need to browse it
         make_array_of_tree_node(node)
      }
   }
}

// Some code
make_array_of_tree_node(rootNode);
// Here I'd like to have access to the array containing all the elements node.title
  • 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-22T21:31:20+00:00Added an answer on May 22, 2026 at 9:31 pm

    You can declare an array like this:

    var nodes = [];
    

    Then you can add things to it with:

    nodes.push(something);
    

    That adds to the end of the array; in that sense it’s kind-of like a list. You can access elements by numeric indexes, starting with zero. The length of the array is maintained for you:

    var len = nodes.length;
    

    What you’ll probably want to do is make the array another parameter of your function.

    edit — To illustrate the pattern, if you’ve got a recursive function:

    function recursive(data, array) {
      if ( timeToStop ) {
        array.push( data.whatever );
      }
      else {
        recursive(data.subData, array);
      }
    }
    

    Then you can use a second function to be the real API that other code will use:

    function actual(data) {
      var array = [];
      recursive(data, array); // fills up the array
      return array;
    }
    

    In JavaScript, furthermore, it’s common to place the “recursive” function inside the “actual” function, which makes the recursive part private and keeps the global namespace cleaner.

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

Sidebar

Related Questions

I need an advice about how to create new string array from 4 different
I need to create a big array in my code, I have the values
I need to create a php array from a very large HTML select list.
Hey all. I need to create an array of first names from another array
i need some help here, i need to know how to create an array
I need some help with the following code... How do I create the array
I am trying to create an expression tree. I need to read data from
I need to create an array by searching a string for occurrences of '['
I need to create an array of arrays. I have been using array_map(null,$a,$b,$c) to
I need to create an array of images in which, every time I tap,

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.