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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:47:36+00:00 2026-06-01T00:47:36+00:00

My problem is as follows. I have an array of objects in the form

  • 0

My problem is as follows. I have an array of objects in the form of source/target from a graph (these are the id’s of the node). It looks like this:

[{"source": 1053, "target": 845, "value": 751}, {"source": 845, "target": 862, "value": 751}, {"source": 1053, "target": 611, "value": 751}, {"source": 1053, "target": 611, "value": 751}, {"source": 1054, "target": 905, "value": 17}, {"source": 1055, "target": 837, "value": 8}, {"source": 1055, "target": 837, "value": 8}, {"source": 1055, "target": 837, "value": 8}, {"source": 1055, "target": 400, "value": 8}, {"source": 1055, "target": 400, "value": 8}, {"source": 1055, "target": 400, "value": 8}]

Now: For a certain node id I would like to know all its children and the subsequent subchildren of these children and so on, all the way down. It works for the first “generation”, but then I would need to iterate over the targets again and again. How do I accomplish this?

nodes = [1053]
function getChildren(nodes, links) {
    var children = [];
    $.each(links, function(key, link) {
        if (nodes.indexOf(link.source) > -1) {
            children.push(link.target);
        }
    });
    return children;
}
  • 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-01T00:47:37+00:00Added an answer on June 1, 2026 at 12:47 am

    The recursion would look like:

    1. Get all children of the given node
    2. if one of them is new to your result array
      • get all of its children and add them
    3. return the result

    …which would be a simple depth-first search.

    function getAllLinkedTo(nodes) {
        var result = [];
        for (var i=0; i<nodes.length; i++)
            getChildren(nodes[i]);
        function getChildren(node) {
            if (result.indexOf(node) > -1)
                return;
            result.push(node);
            for (var i=0; i<links.length; i++) // a source -> targets mapping object would be beneficial
                if (links[i].source == node)
                    getChildren(links[i].target);
        }
        return result;
    }
    

    You could also accomplish this with a loop over result, which may be faster.

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

Sidebar

Related Questions

I have a Profile form that inherits from sfGuardRegisterForm I have these fields: $this->useFields(
I have a mysql problem, my query looks as follows but not complete SELECT
This problem follows on from a previous question . When I run the following
My problem is as follows: I have an array of strings that contain dates
Our situation is as follows, but I'm curious about this problem in any situation.
So I am trying to store an array of objects into localStorage, as follows:-
I have an interesting problem. I need to analyse a source code and to
I have this problem with Cocoa, I am calling a function and passing an
I have an array of objects and I can print them out, so I
My problem looks as follows: I want to make a vote app where People

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.