JSFiddle - React, Tailwind, and code Playground

by thewolff

HTML

<div id="result"></div>

JavaScript

function getObject(theObject) {
    var result = null;
    if(theObject instanceof Array) {
        for(var i = 0; i < theObject.length; i++) {
            result = getObject(theObject[i]);
        }
    }
    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]);
        }
    }
    return result;
}

$(function() {
    var myObject = {message: {error: {message: "418 baby!"}}}
    const mySimpleObject = {message: "simple town!"}
  var result = getObject(myObject);
  getObject(mySimpleObject)
  
  const responseString = {message:`"error":{"message":"Conflict of interest, certifier is admin or owner of the review 87135 in Anvil."}} (Service: SRAMAssignmentServiceLambda; Status Code: 409; Error Code: ConflictOfInterestException; Request ID: a6c2fcbb-3fe0-4983-a8b9-506aeb860462; Proxy: null)`}
  

  
  

    if(result != null) {
        $('#result').html('Found object: <br />');
        for(var prop in result) {
            $('#result').html($('#result').html() + prop + ': ' + result[prop] + '<br />');
        }
    }
    else {
        $('#result').html('Not Found.');
    }   
});