find key in nested json object

function getObject(theObject) {
    var result = null;
    if(theObject instanceof Array) {
        for(var i = 0; i < theObject.length; i++) {
            result = getObject(theObject[i]);
            if (result) {
                break;
            }   
        }
    }
    else
    {
        for(var prop in theObject) {
            console.log(prop + ': ' + theObject[prop]);
            if(prop == 'id') {
                if(theObject[prop] == 1) {
                    return theObject;
                }
            }
            if(theObject[prop] instanceof Object || theObject[prop] instanceof Array) {
                result = getObject(theObject[prop]);
                if (result) {
                    break;
                }
            } 
        }
    }
    return result;
}

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
look up value of a nested key in json javascript find key-value in deeply nested JSON object get key from nested json for to find the value of key in nested json can get value of nested json object get specific element json nested object how to get key of nested json python how to get key nested json search key in nested complex json javascript js function find json value by nested key find keys in nested json object javascript how to gets json keys nested get keys from nested json object in javascript how to access nested json object key and values access nested key value object and array from json access nested key value object and array in json find a particular key in nested json object python get nested object in json get all keys of nested object json data javascript jsonata to get all keys of nested object how to get keys from array of nested json objects take specific keys from nested json structure get key values from nested json string search key in nested complex json how to get the value for a key in json nested object json object get nested keys based on string js json object get nested keys based on string object.keys nested json get value by key in nested json javascript return value by key in nested json javascript how to get key and value from nested json array object in javascript how to get a key from json object from 3 nested array how to get key for nested json object extract key value from nested json get specific key in nested json how find out nested json object value nested key check for json find a key in nested json nested object key search javascript javascript find key in nested object js search every level of object for key javascript how to found key in associative array by value in nested object js find key by value in nested object find key value in nested object javascript js find property in nested object js find value in nested object and get key find key in nested json object
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source