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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:07:53+00:00 2026-06-16T16:07:53+00:00

Here is what I want to do: I have a tree (javascript object-literal structure)

  • 0

Here is what I want to do:

  1. I have a tree (javascript object-literal structure) with multiple levels.
  2. I have a value of a particular key of this object.
  3. I want to search for this exact key-value pair in the structure and return the value of another key as an output.

For clarity following is my object literal:

{
"nodeId": 1081,
"appId": 150,
"displayText": "Welcome here",
"Nodes": [
    {
        "nodeId": 2000,
        "appId": 150,
        "displayText": "Buy",
        "parentNodeId": 1081,
        "Nodes": [
            {
                "nodeId": 2003,
                "appId": 150,
                "displayText": "tCars",
                "parentNodeId": 2000,
                "Nodes": [
                    {
                        "nodeId": 2006,
                        "appId": 150,
                        "displayText": "Diesel",
                        "parentNodeId": 2003,
                        "Nodes": [
                            {
                                "nodeId": 2008,
                                "appId": 150,
                                "displayText": "Price", //This is what I want as return value.
                                "parentNodeId": 2006,
                                "Nodes": [],
                                "nodeCode": "RN_1_1_2_1_3_2_4_1",
                                "parentCode": "RN_1_1_2_1_3_2",
                                "jumpToNode": "RN_1_1" //here is the value that I have with me.
                            }
                        ],
                        "nodeCode": "RN_1_1_2_1_3_2",
                        "parentCode": "RN_1_1_2_1"
                    }
                ],
                "concatWithHeader": false,
                "nodeCode": "RN_1_1_2_1",
                "parentCode": "RN_1_1"
            }
        ],
        "nodeCode": "RN_1_1",
        "parentCode": "RN"
    }
  ],
  "nodeCode": "RN",
  "parentCode": "ROOT_NODE"
}

2. Value that I have with me is “RN_1_1” against jumpToNode

3. I want to search in this object literal and get the value of the key displayText

I searched and tried few things for this but couldnt get the logic to iterate over the inner Nodes objects.

Method I wrote so far:

function getObjects(tree){
var searchkey="RN_1_1";
var displayText = "displayText";
var nodeCode = "nodeCode";
var returnText;

if (tree.hasOwnProperty(nodeCode)) {
   var obj = tree[nodeCode];

   if(obj == searchkey){
    returnText = tree[displayText]; //gives me the return text
    break;
   }
   else{
    //here I should iterate over the inner `Nodes` and get the required value.
   }
}
}

Please help.

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-06-16T16:07:55+00:00Added an answer on June 16, 2026 at 4:07 pm

    I think you can do something like this which works recursively:

    function findProperty(obj, prop, val, propToFetch) {
        var answer;
        if (obj.hasOwnProperty(prop) && obj[prop] === val) {
            return obj[propToFetch];
        }
        for (var i = 0, len = obj.Nodes.length; i < len; i++) {
            answer = findProperty(obj.Nodes[i], prop, val, propToFetch);
            if (answer !== null) {return answer;}
        }
        return null;
    }
    
    var result = findProperty(data, "jumpToNode", "RN_1_1", "displayText");
    

    Working demo here: http://jsfiddle.net/jfriend00/EjC5V/

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

Sidebar

Related Questions

To explain my question I have created this http://jsfiddle.net/Jams/XNVB2/ here I want when div1
I have this code which iterates over a tree, doing a depth-first search. Every
Here I have a dom tree parsed from a html page. I want to
Placing an image inside a Span (here : HtmlGenericControl ) programmatically Want to have
I want to have a page redirect to another. Here is the situation: I
Here i want to do UDP Socket programming in C. I have one device
I want to have a UIImage as a background image on a UIView. Here
James here. I'm working on a site that I want to have the same
I work for a travel agency, they have a website, from here they want
Here is what I want to achieve: I have RadGridView, let's call it gridView,

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.