Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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;
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: counter random interval 
Javascript :: eslint failed to load react 
Javascript :: date change error 
Javascript :: api call in react chart 
Javascript :: JavaScript URL Parse including pathname 
Javascript :: Example of Private Class Methods and Accessors in es12 
Javascript :: Example code of using inner blocks in Wordpress with ES5 
Javascript :: Key and property shorthand in ES6 
Javascript :: golang json time 
Javascript :: add script tag change on every new page in angular 8 
Javascript :: cypress contains regex 
Javascript :: find a node that match a spesific selector string in the paren 
Javascript :: Replace all ocourrences in JS 
Javascript :: change user agent in playwright 
Javascript :: react break out of useeffect 
Javascript :: How do you convert VARCHAR to TIMESTAMP 
Javascript :: salman javascript id 
Javascript :: convert path string to url encoding javascript 
Javascript :: browserslist 
Javascript :: mouselight js 
Javascript :: initialize back4app 
Javascript :: vue js key modifiers 
Javascript :: axios 401 unauthorized refresh token multipal request 
Javascript :: kubernetes get cluster 
Javascript :: string to number javascript & remove text 
Javascript :: catch the last item in a array js 
Javascript :: geocoding react 
Javascript :: functiong of array sort 
Javascript :: how to add,delete,update property in javascript object 
Javascript :: please run 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =